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

Add uuid! macro to produce compile-time Uuids from strings. #395

Closed
wants to merge 1 commit into from

Conversation

mehcode
Copy link
Contributor

@mehcode mehcode commented Apr 7, 2019

I'm submitting a(n) feature|refactor

Description

This moves out parsing into its own crate, uuid-parser; and, adds a third crate, uuid-macros, with a single expression proc-macro uuid! that can produce compile-time UUIDs from strings.

As this is a pretty invasive refactor, please let me know if there are changes to the organization you'd like me to make.

Motivation

Replaces:

let id = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap();

With:

let id = uuid!("550e8400-e29b-41d4-a716-446655440000");

Furthermore, after #394, this enables const UUIDs to be const themselves.

const ID: Uuid = uuid!("550e8400-e29b-41d4-a716-446655440000");

Tests

A new test was added to showcase uuid! and prove it works.

Related Issue(s)

@todo
Copy link

todo bot commented Apr 7, 2019

explain multiple segment count.

Parsers can expect a range of Uuid segment count.


// TODO: explain multiple segment count.
// BODY: Parsers can expect a range of Uuid segment count.
// This needs to be expanded on.
expected: Expected,
/// The number of segments found.
found: usize,


This comment was generated by todo based on a TODO comment in 1a4d28c in #395. cc @mehcode.

@todo
Copy link

todo bot commented Apr 7, 2019

explain multiple lengths.

Parsers can expect a range of Uuid lenghts.


// TODO: explain multiple lengths.
// BODY: Parsers can expect a range of Uuid lenghts.
// This needs to be expanded on.
expected: Expected,
/// The invalid length found.
found: usize,


This comment was generated by todo based on a TODO comment in 1a4d28c in #395. cc @mehcode.

@todo
Copy link

todo bot commented Apr 7, 2019

remove the u8 cast

this only needed until we switch to


uuid/uuid-parser/src/lib.rs

Lines 192 to 197 in 1a4d28c

// TODO: remove the u8 cast
// BODY: this only needed until we switch to
// ParseError
if ACC_GROUP_LENS[group] as u8 != digit {
// Calculate how many digits this group consists of
// in the input.


This comment was generated by todo based on a TODO comment in 1a4d28c in #395. cc @mehcode.

@todo
Copy link

todo bot commented Apr 7, 2019

remove the u8 cast

this only needed until we switch to


uuid/uuid-parser/src/lib.rs

Lines 199 to 204 in 1a4d28c

// TODO: remove the u8 cast
// BODY: this only needed until we switch to
// ParseError
digit - ACC_GROUP_LENS[group - 1] as u8
} else {
digit


This comment was generated by todo based on a TODO comment in 1a4d28c in #395. cc @mehcode.

@todo
Copy link

todo bot commented Apr 7, 2019

remove the u8 cast

this only needed until we switch to


uuid/uuid-parser/src/lib.rs

Lines 240 to 245 in 1a4d28c

// TODO: remove the u8 cast
// BODY: this only needed until we switch to
// ParseError
digit - ACC_GROUP_LENS[group - 1] as u8
} else {
digit


This comment was generated by todo based on a TODO comment in 1a4d28c in #395. cc @mehcode.

@todo
Copy link

todo bot commented Apr 7, 2019

remove the u8 cast

this only needed until we switch to


uuid/uuid-parser/src/lib.rs

Lines 270 to 275 in 1a4d28c

// TODO: remove the u8 cast
// BODY: this only needed until we switch to
// ParseError
if ACC_GROUP_LENS[4] as u8 != digit {
return Err(ParseError::InvalidGroupLength {
expected: Expected::Exact(GROUP_LENS[4]),


This comment was generated by todo based on a TODO comment in 1a4d28c in #395. cc @mehcode.

@kinggoesgaming
Copy link
Member

kinggoesgaming commented Apr 7, 2019

Thanks for this PR. However I am not yet comfortable with including this into the main crate. However we have an inactive crate (uuid-rs/uuid_macro) which was designed for this for this purpose (polish it out and then introduced). I would love if you open this again that.

And post that I think it would be a good point to publish that crate aswell

@mehcode
Copy link
Contributor Author

mehcode commented Apr 7, 2019

That crate looks similar enough. I hadn't noticed it. Though I don't see how I could improve the crate much (from a quick glance) without the split here to move out uuid-parser.

I'd recommend renaming it to uuid-macros though. Never know when we might want a second one.

@mehcode mehcode closed this Apr 7, 2019
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