@@ -33,7 +33,7 @@ use std::{borrow::Cow, ops::Deref};
3333/// ```rust
3434/// # use parquet_variant::{VariantPath, VariantPathElement};
3535/// // access the field "foo" in a variant object value
36- /// let path = VariantPath::from ("foo");
36+ /// let path = VariantPath::try_from ("foo").unwrap( );
3737/// // access the first element in a variant list vale
3838/// let path = VariantPath::from(0);
3939/// ```
@@ -43,7 +43,7 @@ use std::{borrow::Cow, ops::Deref};
4343/// # use parquet_variant::{VariantPath, VariantPathElement};
4444/// /// You can also create a path by joining elements together:
4545/// // access the field "foo" and then the first element in a variant list value
46- /// let path = VariantPath::from ("foo").join(0);
46+ /// let path = VariantPath::try_from ("foo").unwrap( ).join(0);
4747/// // this is the same as the previous one
4848/// let path2 = VariantPath::from_iter(["foo".into(), 0.into()]);
4949/// assert_eq!(path, path2);
@@ -59,8 +59,8 @@ use std::{borrow::Cow, ops::Deref};
5959/// ```
6060/// # use parquet_variant::{VariantPath, VariantPathElement};
6161/// /// You can also convert strings directly into paths using dot notation
62- /// let path = VariantPath::from ("foo.bar.baz");
63- /// let expected = VariantPath::from ("foo").join("bar").join("baz");
62+ /// let path = VariantPath::try_from ("foo.bar.baz").unwrap( );
63+ /// let expected = VariantPath::try_from ("foo").unwrap( ).join("bar").join("baz");
6464/// assert_eq!(path, expected);
6565/// ```
6666///
@@ -69,11 +69,21 @@ use std::{borrow::Cow, ops::Deref};
6969/// # use parquet_variant::{VariantPath, VariantPathElement};
7070/// /// You can access the paths using slices
7171/// // access the field "foo" and then the first element in a variant list value
72- /// let path = VariantPath::from ("foo")
72+ /// let path = VariantPath::try_from ("foo").unwrap( )
7373/// .join("bar")
7474/// .join("baz");
7575/// assert_eq!(path[1], VariantPathElement::field("bar"));
7676/// ```
77+ ///
78+ /// # Example: Accessing filed with bracket
79+ /// ```
80+ /// # use parquet_variant::{VariantPath, VariantPathElement};
81+ /// let path = VariantPath::try_from("a[b.c].d[2]").unwrap();
82+ /// let expected = VariantPath::from_iter([VariantPathElement::field("a"),
83+ /// VariantPathElement::field("b.c"),
84+ /// VariantPathElement::field("d"),
85+ /// VariantPathElement::index(2)]);
86+ /// assert_eq!(path, expected)
7787#[ derive( Debug , Clone , PartialEq , Default ) ]
7888pub struct VariantPath < ' a > ( Vec < VariantPathElement < ' a > > ) ;
7989
0 commit comments