-
Notifications
You must be signed in to change notification settings - Fork 612
minor: Implement common traits for OneOrManyWithParens #1368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pull Request Test Coverage Report for Build 10434835580Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, cc @alamb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gstvg -- can you please add a test showing what this contribution allows? That way we won't accidentally break it in the future
Marking as draft as I think this PR is no longer waiting on feedback. Please mark it as ready for review when it is ready for another look |
…nto deref_one_or_many_with_parens
Sure, it makes sense, so much so that while I was writing it, I realized it wasn't enough for my intended usage 😅 |
src/ast/mod.rs
Outdated
OneOrManyWithParens::Many(many) => (None, many), | ||
}; | ||
|
||
one.into_iter().chain(many) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit strange, it could be
vec![one]
and just returnVec::into_iter
, but it allocates, or- create and implement a new iterator, but it's much more work, and we won't get for free additional iterator traits impls.
Just let me know if other approach is preferable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create and implement a new iterator, but it's much more work, and we won't get for free additional iterator traits impls.
this is what i would have expected.
Not sure what you mean "won't get for free additional iterator traits impl"
Another potential approach is returning a Box
ed iterator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't too much work after all 😬
Not sure what you mean "won't get for free additional iterator traits impl"
It's actually just DoubleEndedIterator
, I thought there were more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gstvg -- this is looking close
src/ast/mod.rs
Outdated
OneOrManyWithParens::Many(many) => (None, many), | ||
}; | ||
|
||
one.into_iter().chain(many) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create and implement a new iterator, but it's much more work, and we won't get for free additional iterator traits impls.
this is what i would have expected.
Not sure what you mean "won't get for free additional iterator traits impl"
Another potential approach is returning a Box
ed iterator
@@ -1004,6 +1005,51 @@ pub enum OneOrManyWithParens<T> { | |||
Many(Vec<T>), | |||
} | |||
|
|||
impl<T> Deref for OneOrManyWithParens<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good -- I think if we are going to add this code we should also add examples to the documentation f OneOrManyWithParens
otherwise it will likely be hard to find
So like
/// # Example: accessing as a slice:
/// ...
/// # Example: iterating
/// ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
…nto deref_one_or_many_with_parens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me -- thank you @gstvg and I apologize for the delay in reviewing
This allows accessing all inner values without matching