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

Tweak bril-rs library #96

Merged
merged 6 commits into from
Dec 13, 2020
Merged

Tweak bril-rs library #96

merged 6 commits into from
Dec 13, 2020

Conversation

nwtnni
Copy link
Contributor

@nwtnni nwtnni commented Dec 13, 2020

Hello,

I'm hoping to work through the self-guided course over the next few weeks, and found some minor things in bril-rs that I would write differently. I can revert any of the changes I've made here as well!

Thanks,
Newton

The `#[serde(default)]` attribute will correctly handle missing fields
and deserialize to an empty `Vec<T>`, which is easier to work with.
This is more of a stylistic choice: [raw identifiers][ri] are a
bit ugly, but allow us to stick closer to the syntax reference.

[ri]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/raw-identifiers.html
Deriving [`Copy`][cp] in particular makes life a lot easier.

[cp]: https://doc.rust-lang.org/beta/core/marker/trait.Copy.html
@Pat-Lafon
Copy link
Contributor

Hey, while we are fixing things, can I hijack this to also get rid of the double and in the docs rust.md line 20? (My bad)

Its personal preference but I would disagree with 466490b. One of the listed reasons for #[serde(rename)] is specifically to handle the case of reserved Rust keywords so that you don't need to use raw identifiers. I'm amused to find a serde issue with this exact example. Clippy unfortunately doesn't have a preference on this but at least four people on r/rust might agree with me.

We should probably check with @sampsyo that there are no plans to add a String extension/String literal to Bril. A Literal::String(String) would not be copy-able so bril-rs would end up with a rather unnecessary breaking change if it reverts that trait.

Everything else looks like a clear improvement.

@sampsyo
Copy link
Owner

sampsyo commented Dec 13, 2020

Yo, @Pat-Lafon—feel free to open a mini-PR just for that. 😃 No shame in small PRs!

@sampsyo
Copy link
Owner

sampsyo commented Dec 13, 2020

Hi, @nwtnni—great to hear from you!! I hope you're well.

I'll defer to @Pat-Lafon, who wrote this stuff, about the whole #[serde(rename)] thing. I think adding Copy to the data structures should be fine—if we ever wanted to add strings or other "large" constant data, we'd probably want to figure out some other way of storing it.

@nwtnni
Copy link
Contributor Author

nwtnni commented Dec 13, 2020

Thanks for the feedback and for creating the crate, @Pat-Lafon! And hello @sampsyo! Thanks for making the course so accessible :) I was reminded when I saw a couple links to it on reddit haha.

Its personal preference but I would disagree with 466490b. One of the listed reasons for #[serde(rename)] is specifically to handle the case of reserved Rust keywords so that you don't need to use raw identifiers.

Sure, I'll go ahead and revert that commit.

We should probably check with @sampsyo that there are no plans to add a String extension/String literal to Bril. A Literal::String(String) would not be copy-able so bril-rs would end up with a rather unnecessary breaking change if it reverts that trait.

Hmm, thanks for raising that point. I'm actually also leaning toward not deriving Copy to be conservative, since it's just a minor ergonomics thing.

@sampsyo
Copy link
Owner

sampsyo commented Dec 13, 2020

LGTM. Happy to merge further PRs from either of y'all, of course.

@sampsyo sampsyo merged commit 1267598 into sampsyo:master Dec 13, 2020
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.

None yet

3 participants