Skip to content

Misc changes #193

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 4 commits into from
Apr 3, 2021
Merged

Misc changes #193

merged 4 commits into from
Apr 3, 2021

Conversation

matthiasbeyer
Copy link
Member

These are misc changes that I'd like to merge. Each patch is one change that could be debated over.


I'm not gonna merge this before some discussion happened.

This patch simplifies the Source::collect_to() default implementation by
making use of the ? operator as well as the std::iter API.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Copy link
Contributor

@szarykott szarykott left a comment

Choose a reason for hiding this comment

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

Except for the comments I left, everything is super fine!

src/value.rs Outdated
}

ValueKind::Table(r)
ValueKind::Table(values.into_iter().map(|(k, v)| (k, v.into())).collect())
Copy link
Contributor

Choose a reason for hiding this comment

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

The new version is surely much more concise!

But on the other hand, it is harder to understand (at least for me). Maybe for the sake of readability, it could be made into two-liner like

let map = HashMap::from_iter(...);
ValueKind::Table(map)

And to be sure that strings are reused drain could be used since function takes the ownership of values either way? Possibly this is what into_iter does, but I am not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for that comment. I will push a fixup commit for splitting the line into two shortly.

Using HashMap::drain is not what we want here, because it keeps the hashmap allocated for later use. HashMap::into_iter() takes ownership and with collect()ing it into a new HashMap object of HashMap<String, Value>. That's exactly what we want here, so that part is fine.

Thanks again for your comment!

@matthiasbeyer matthiasbeyer added this to the 0.12.0 milestone Mar 31, 2021
src/value.rs Outdated
@@ -107,8 +96,15 @@ impl Display for ValueKind {
ValueKind::Nil => write!(f, "nil"),

// TODO: Figure out a nice Display for these
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this TODO still relevant?

@matthiasbeyer matthiasbeyer marked this pull request as ready for review April 1, 2021 14:56
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This patch changes the Display impl for ValueKind so that Array and
Table are nicely displayed.
This basically changes a user-facing implementation in a
non-backwards-compatible way. But as the documentation for std states:

    Display is similar to Debug, but Display is for user-facing output
    [...]

This is user-facing and I'd say this is okay.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
@matthiasbeyer
Copy link
Member Author

Because you already approved, I'm gonna squash now.

@szarykott
Copy link
Contributor

Feel free to merge.

@matthiasbeyer matthiasbeyer merged commit d548ffe into rust-cli:master Apr 3, 2021
@matthiasbeyer matthiasbeyer deleted the misc branch April 3, 2021 15:18
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.

2 participants