Skip to content
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

Update AST builder ExprNode & ExprList to accept borrowed values #967

Merged
merged 1 commit into from
Oct 23, 2022

Conversation

panarch
Copy link
Member

@panarch panarch commented Oct 23, 2022

Update ExprNode & ExprList to accept both String and &str to build ExprNode.
Update ExprList to accept both owned vector and borrowed slice.

e.g. ExprList

        // Vec<Into<ExprNode>>
        let actual: ExprList = vec!["id", "name"].into();
        let expected = "id, name";
        test(actual, expected);

        // Vec<ExprNode>
        let actual: ExprList = vec![col("id"), col("name")].into();
        let expected = "id, name";
        test(actual, expected);

        // &Vec<ExprNode>
        let actual = vec!["id", "name"];
        let actual: ExprList = (&actual).into();
        let expected = "id, name";
        test(actual, expected);

        // &[Into<ExprNode>]
        let actual = vec!["rate / 10", "col1"];
        let actual: ExprList = actual.as_slice().into();
        let expected = "rate / 10, col1";
        test(actual, expected);

        // &[ExprNode]
        let actual = vec![col("id"), col("name")];
        let actual: ExprList = actual.as_slice().into();
        let expected = "id, name";
        test(actual, expected);

@panarch panarch added the improvement Improvements for existing features label Oct 23, 2022
@panarch panarch self-assigned this Oct 23, 2022
@coveralls
Copy link

Pull Request Test Coverage Report for Build 3306764259

  • 123 of 123 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 97.892%

Totals Coverage Status
Change from base Build 3303918887: 0.08%
Covered Lines: 38227
Relevant Lines: 39050

💛 - Coveralls

Copy link
Member

@ever0de ever0de left a comment

Choose a reason for hiding this comment

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

Looks good 👍 👍 👍 👍 👍

Comment on lines +64 to +69
let exprs = exprs.into_owned();

exprs
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>>>()
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/rust-lang/rust-clippy/blob/967f172e256802f9bf0ad5718d9c761da18132a9/clippy_lints/src/methods/unnecessary_to_owned.rs#L198-L239

It gives an unnecessary_to_owned clippy error, and clippy tells you to fix it like this:

T.iter().cloned()

But it seems rather unnecessary referencing.
The behavior of into_owned is only to strip the enum when Cow::Owned, whereas Iterator::cloned calls Clone::clone.

So we separated it like this.

@panarch panarch merged commit 80ebf7a into main Oct 23, 2022
@panarch panarch deleted the exprnode-to-get-borrowed-values branch October 23, 2022 11:00
devgony pushed a commit to devgony/gluesql that referenced this pull request Oct 29, 2022
…esql#967)

Update ExprNode & ExprList to accept both String and &str to build ExprNode.
Update ExprList to accept both owned vector and borrowed slice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvements for existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants