alamb commented on code in PR #7740:
URL: https://github.com/apache/arrow-rs/pull/7740#discussion_r2162606284


##########
parquet-variant/src/builder.rs:
##########
@@ -148,189 +318,112 @@ fn make_room_for_header(buffer: &mut Vec<u8>, 
start_pos: usize, header_size: usi
 ///
 /// # Example: [`Variant::List`] of  [`Variant::Object`]s
 ///
-/// THis example shows how to create an list  of objects:
+/// This example shows how to create an list of objects:
 /// ```json
 /// [
-///  {
-///   "first_name": "Jiaying",
-///  "last_name": "Li"
-/// },
 ///   {
-///    "first_name": "Malthe",
-///    "last_name": "Karbo"
-/// }
+///      "id": 1,
+///      "type": "Cauliflower"
+///   },
+///   {
+///      "id": 2,
+///      "type": "Beets"
+///   }
 /// ]
 /// ```
+/// ```
+/// use parquet_variant::{Variant, VariantBuilder};
+/// let mut builder = VariantBuilder::new();
+///
+/// // Create a builder that will write elements to the list
+/// let mut list_builder = builder.new_list();
+///
+/// {
+///     let mut object_builder = list_builder.new_object();
+///     object_builder.append_value("id", 1);
+///     object_builder.append_value("type", "Cauliflower");
+///     object_builder.finish();
+/// }
+///
+/// {
+///     let mut object_builder = list_builder.new_object();
+///     object_builder.append_value("id", 2);
+///     object_builder.append_value("type", "Beets");
+///     object_builder.finish();
+/// }
+///
+/// list_builder.finish();
+/// // Finish the builder to get the metadata and value
+/// let (metadata, value) = builder.finish();
+/// // use the Variant API to verify the result
+/// let variant = Variant::try_new(&metadata, &value).unwrap();
+/// let Variant::List(variant_list) = variant else {
+///   panic!("unexpected variant type");
+/// };

Review Comment:
   While reading this example, it seems like it would be more convenient if we 
could write this like
   
   ```suggestion
   /// let variant_list = variant.as_list().expect("unexpected variant type");
   ```
   
   I think that type of accessor is similar to the existng `as_null`, `as_i32,` 
etc APIs. 
   
   - I made https://github.com/apache/arrow-rs/pull/7755



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to