Skip to content

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

Merged
merged 6 commits into from
Sep 10, 2024

Conversation

gstvg
Copy link
Contributor

@gstvg gstvg commented Aug 7, 2024

This allows accessing all inner values without matching

@coveralls
Copy link

coveralls commented Aug 7, 2024

Pull Request Test Coverage Report for Build 10434835580

Details

  • 71 of 71 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 89.167%

Totals Coverage Status
Change from base Build 10418247467: 0.03%
Covered Lines: 28363
Relevant Lines: 31809

💛 - Coveralls

Copy link
Contributor

@jmhain jmhain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, cc @alamb

Copy link
Contributor

@alamb alamb left a 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

@alamb
Copy link
Contributor

alamb commented Aug 13, 2024

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

@alamb alamb marked this pull request as draft August 13, 2024 11:00
@gstvg
Copy link
Contributor Author

gstvg commented Aug 18, 2024

Thanks @gstvg -- can you please add a test showing what this contribution allows? That way we won't accidentally break it in the future

Sure, it makes sense, so much so that while I was writing it, I realized it wasn't enough for my intended usage 😅
I ended up implementing 3 more traits
Thanks @jmhain and @alamb

src/ast/mod.rs Outdated
OneOrManyWithParens::Many(many) => (None, many),
};

one.into_iter().chain(many)
Copy link
Contributor Author

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

  1. vec![one] and just return Vec::into_iter, but it allocates, or
  2. 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

Copy link
Contributor

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 Boxed iterator

Copy link
Contributor Author

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

@gstvg gstvg marked this pull request as ready for review August 18, 2024 15:16
@gstvg gstvg changed the title minor: Implement Deref<Target=[T]> for OneOrManyWithParens<T> minor: Implement common traits for OneOrManyWithParens Aug 18, 2024
Copy link
Contributor

@alamb alamb left a 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)
Copy link
Contributor

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 Boxed iterator

@@ -1004,6 +1005,51 @@ pub enum OneOrManyWithParens<T> {
Many(Vec<T>),
}

impl<T> Deref for OneOrManyWithParens<T> {
Copy link
Contributor

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
/// ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

@alamb alamb left a 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

@alamb alamb merged commit 8305c5d into apache:main Sep 10, 2024
10 checks passed
@alamb
Copy link
Contributor

alamb commented Sep 10, 2024

Thanks again @gstvg and @jmhain

@gstvg
Copy link
Contributor Author

gstvg commented Sep 11, 2024

Thanks @jmhain and @alamb 🙏

This looks good to me -- thank you @gstvg and I apologize for the delay in reviewing

It's okay, don't worry. If I ever need something to be reviewed with priority, I will ping you or another maintainer

ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants