-
Notifications
You must be signed in to change notification settings - Fork 192
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 a version of Uuid::from_fields
that can't fail
#150
Comments
Hi Ted, Thanks. We will look into this. Instead of having seperate functions, I would prefer if we could use generics for this, if possible. The earliest we can get this implemented & released is either 0.6.1 or 0.7.0. Also you are free to send us a PR implementing this. |
I'm not sure what precisely you'd want to do with generics here, can you clarify? |
I was thinking if we could have just one function that returns the UUID irrespective of data. But I think that won't be possible. Will add the function as you proposed. |
It's not quite the same as the proposed |
Oh, that is indeed very similar. In the uses I've found I can't just pass |
I think that's a niche case, that should technically be handled by the library user before passing it to the library. |
I am doing so, I just then don't have a method on |
@luser Can I see an example of how you are using this? Perhaps it might help get a better understanding on this |
Sure. This code hasn't actually landed anywhere yet, but it's a proposed patch to |
Looking again at this, i feel that having a similar method with the only change being a different return type doesn't make much sense to me. It will add more cost ot the maintainence later and there isn't much gain including it. We could provide a function to unwrap but then it will be the same as calling unwrap from outside and there is no visible gain in it. |
You are probably right. I think in the future when we have const generics and it's possible to easily get a reference to an array of a specific size from a slice designing APIs that use exactly-sized array references will be more ergonomic. |
I’ve ended up circling back around to this while making a lot more things The approach I was thinking of was to make That would make |
Uuid::from_fields
takes an&[u8]
ford4
, so it will return an error ifd4
is not 8 bytes in length. Every time I've used this method I've had an 8 byte array to hand, so it seems silly to have to callunwrap
on the result. It would be nice if there was a version of this likefn from_fields(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Uuid
.I realize that working with arrays is sort of a pain in Rust for several reasons. Once the const generics RFC gets implemented it should make some things simpler, like making it possible to have a method on slices that returns an array reference of a certain size.
The text was updated successfully, but these errors were encountered: