Support V4 Uuids from arbitrary random bytes #170

Closed
opened 2018-03-16 19:35:24 -05:00 by KodrAus · 5 comments
KodrAus commented 2018-03-16 19:35:24 -05:00 (Migrated from github.com)

Note: for support questions, please use gitter or users forums. This
repository's issues are reserved for feature requests and bug reports.

I'm submitting a ...

  • bug report
  • feature request
  • support request => Please do not submit support request here, see note
    at the top of this template.

Description

I thought we could flesh out our solution to creating uuids using alternative Rngs without having to make rand a public dependency.

new_v4_bat_scooter_name_not_important

https://github.com/servo/servo/issues/20306 suggested a new_v4_from_bytes method as a workaround to needing to make rand a public dependency. Following the naming convention for other constructors, it might look like:

fn new_v4_from_bytes(b: &[u8]) -> Result<Uuid, ParseError>;
let uuid = Uuid::new_v4_from_bytes(b).expect("invalid length");

It would be nice to use [u8; 16] as the source instead of &[u8] so we can make the method infallible. It would be a bit inconsistent to use fn new_v4_from_bytes(b: [u8; 16]) since we already have fn from_bytes(b: &[u8]). new_v4_from_uuid_bytes is a bit of a nasty name. So for now it could be:

fn new_v4_bat_scooter_name_not_important(b: [u8; 16]) -> Uuid;
let uuid = Uuid::new_v4_bat_scooter_name_not_important(b);

We could even go ahead and name it something like new_v4_from_rng_bytes([u8; 16]) and deprecate it once rand is stable in favour of Rand::rand.

Builder

Edit: Moved to a seperate issue #171

Related to: #153

cc: @nox @kinggoesgaming @Dylan-DPC

**Note: for support questions, please use [gitter] or [users forums]**. This repository's issues are reserved for feature requests and bug reports. [gitter]: https://gitter.im/uuid-rs/Lobby [users forums]: https://users.rust-lang.org **I'm submitting a ...** - [ ] bug report - [x] feature request - [ ] support request => Please do not submit support request here, see note at the top of this template. # Description I thought we could flesh out our solution to creating uuids using alternative `Rng`s without having to make `rand` a public dependency. ## `new_v4_bat_scooter_name_not_important` https://github.com/servo/servo/issues/20306 suggested a `new_v4_from_bytes` method as a workaround to needing to make `rand` a public dependency. Following the naming convention for other constructors, it might look like: ```rust fn new_v4_from_bytes(b: &[u8]) -> Result<Uuid, ParseError>; ``` ```rust let uuid = Uuid::new_v4_from_bytes(b).expect("invalid length"); ``` It would be nice to use `[u8; 16]` as the source instead of `&[u8]` so we can make the method infallible. It would be a bit inconsistent to use `fn new_v4_from_bytes(b: [u8; 16])` since we already have `fn from_bytes(b: &[u8])`. `new_v4_from_uuid_bytes` is a bit of a nasty name. So for now it could be: ```rust fn new_v4_bat_scooter_name_not_important(b: [u8; 16]) -> Uuid; ``` ```rust let uuid = Uuid::new_v4_bat_scooter_name_not_important(b); ``` We could even go ahead and name it something like `new_v4_from_rng_bytes([u8; 16])` and deprecate it once `rand` is stable in favour of `Rand::rand`. ## `Builder` Edit: Moved to a seperate issue #171 Related to: #153 cc: @nox @kinggoesgaming @Dylan-DPC
kinggoesgaming commented 2018-03-16 21:41:38 -05:00 (Migrated from github.com)

We could even go ahead and name it something like new_v4_from_rng_bytes([u8; 16]) and deprecate it once rand is stable in favour of Rand::rand.

I like this name, as it clearly gets the meaning across.

Edit: removed suggestion on using #[unstable] attribute.


As per the Builder I think I will give it some thought before giving any comments on it.

> We could even go ahead and name it something like `new_v4_from_rng_bytes([u8; 16])` and deprecate it once rand is stable in favour of `Rand::rand`. I like this name, as it clearly gets the meaning across. Edit: removed suggestion on using `#[unstable]` attribute. --- As per the `Builder` I think I will give it some thought before giving any comments on it.
nox commented 2018-03-16 21:43:27 -05:00 (Migrated from github.com)

I would use random instead of rng in the name. What do you mean by #[unstable]?

I would use `random` instead of `rng` in the name. What do you mean by `#[unstable]`?
kinggoesgaming commented 2018-03-16 21:50:22 -05:00 (Migrated from github.com)

wait nevermind, ignore that #[unstable] I sometimes forget that unstable is std specific attribute

wait nevermind, ignore that `#[unstable]` I sometimes forget that `unstable` is `std` specific attribute
Dylan-DPC-zz commented 2018-03-17 05:53:49 -05:00 (Migrated from github.com)

Will give it a try today :)

Edit: Have moved Builder Pattern to a seperate issue #171

Will give it a try today :) Edit: Have moved Builder Pattern to a seperate issue #171
kinggoesgaming commented 2018-03-20 16:54:26 -05:00 (Migrated from github.com)

done

done
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-uuid-rs/uuid#170
No description provided.