Skip to content

Commit 00a2f73

Browse files
sdf-jklKonstantin.Tarasov
andauthored
[Variant] impl FromIterator for VariantPath (#8011)
# Which issue does this PR close? We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. - Closes #7955. # Rationale for this change Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. # What changes are included in this PR? There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. # Are these changes tested? We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? # Are there any user-facing changes? If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please call them out. --------- Co-authored-by: Konstantin.Tarasov <[email protected]>
1 parent 1d9afbc commit 00a2f73

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

parquet-variant/src/path.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ use std::{borrow::Cow, ops::Deref};
4343
/// // access the field "foo" and then the first element in a variant list value
4444
/// let path = VariantPath::from("foo").join(0);
4545
/// // this is the same as the previous one
46-
/// let path2 = VariantPath::new(vec!["foo".into(), 0.into()]);
46+
/// let path2 = VariantPath::from_iter(["foo".into(), 0.into()]);
4747
/// assert_eq!(path, path2);
4848
/// // you can also create a path from a vector of `VariantPathElement` directly
49-
/// let path3 = VariantPath::new(vec![
49+
/// let path3 = [
5050
/// VariantPathElement::field("foo"),
5151
/// VariantPathElement::index(0)
52-
/// ]);
52+
/// ].into_iter().collect::<VariantPath>();
5353
/// assert_eq!(path, path3);
5454
/// ```
5555
///
@@ -109,6 +109,13 @@ impl<'a> From<usize> for VariantPath<'a> {
109109
}
110110
}
111111

112+
/// Create from iter
113+
impl<'a> FromIterator<VariantPathElement<'a>> for VariantPath<'a> {
114+
fn from_iter<T: IntoIterator<Item = VariantPathElement<'a>>>(iter: T) -> Self {
115+
VariantPath::new(Vec::from_iter(iter))
116+
}
117+
}
118+
112119
impl<'a> Deref for VariantPath<'a> {
113120
type Target = [VariantPathElement<'a>];
114121

0 commit comments

Comments
 (0)