-
Notifications
You must be signed in to change notification settings - Fork 13.3k
uuid!()
and iota!()
(and maybe random!()
) syntax extensions
#7104
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
Comments
I really, really dislike the name |
After consideration I don't think that |
Ah, fair point. Would need a typed declaration. |
@cmr concerning the name |
Oh I see, you pointed out the languages that have it (including D, I didn't see!) but just think it's inconsistently used. Hmm. I dunno. This is a syntax extension. It's not like you're going to call it without awareness of what it's for. I guess I'm curious what else you'd want here instead? The use case is:
In order to define an arbitrary sequence of values that you don't care about the numbering of, just "one more than previous". Similar to use in an enum. I suppose most of the time this can be done as:
It's just a lot wordier (have to repeat each variant) and more prone to copy-paste errors. |
I agree that it's nice to have, but I'd call it incr_id!() or something. |
I actually feel like |
Addresses part of #7104 This module adds the ability to generate UUIDs (on all Rust-supported platforms). I reviewed the existing UUID support in libraries for a range of languages; Go, D, C#, Java and Boost++. The features were all very similar, and this patch essentially covers the union. The implmentation is quite straightforward, and uses the underlying rng support which is assumed to be sufficiently strong for this purpose. This patch is not complete, however I have put this up for review to gather feedback before finalising. It has tests for most features and documentation for most functions. Outstanding issues: * Only generates V4 (Random) UUIDs. Do we want to support the SHA-1 hash based flavour as well? * Is it worth having the field-based struct public as well as the byte array? * Formatting the string with '-' between groups not done yet. * Parsing full string not done as there appears to be no regexp support yet. I can write a simple manual parser for now? * D has a generator as well. This would be easy to add. However, given the simple interface for creating a new one, and the presence of the macro, is this useful? * Is it worth having a separate UUID trait and specific implementation? Or should it just have a struct+impl with the same name? Currently it feels weird to have the trait (which can't be named UUID so as to conflict) a separate thing. * Should the macro be visible at the top level scope? As this is a first attempt, some code may not be idiomatic. Please comment below... Thanks for all feedback!
Just a bug, de-nominating |
I am not quite sure why we need
as it would make the resets clear. One can also align the argument like
|
Does something like this look right? https://gist.github.com/pongad/8968393 |
Old bug, demand has subsided. I don't think there's any value keeping it around. |
uuid!()
should generate a UUID (http://en.wikipedia.org/wiki/Universally_unique_identifier). It should take arguments (or there should be multiple variants of the call) to indicate the UUID-variant. The default should just be random. Could possibly defer to arandom!()
syntax extension that generates a random value at compile time.iota!()
should do something like what theiota
expression in Go does: http://golang.org/ref/spec#Iota -- evaluate to a constant integer starting from zero and increment the counter, resetting on some reaosnable boundary such as "per module" or "per scope".(Nominating for feature complete.)
The text was updated successfully, but these errors were encountered: