-
Notifications
You must be signed in to change notification settings - Fork 191
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
API Nits/general "I had trouble with this" #461
Comments
Just remembered serde was a thing so also that Uuid, a fixed size array, is serialized as a slice, issue #329, and it really probably should become the default instead of needing the compact adapter? |
I'd like to add that I got bit by the "v4" feature requiring |
Ah, we do actually support creating random // Some external source of randomness that gives a `[u8; 16]`
let random_bytes = rng();
let uuid = Builder::from_bytes(random_bytes)
.set_variant(Variant::RFC4122)
.set_version(Version::Random)
.build(); We could probably call this out in the docs for |
I've spent some time on this and I think we've fixed up a lot of these papercuts now. There are links in the issues that were split from this one, but we now:
I'll go ahead and close this one now. Any new issues or papercuts that come up in the future would be great to track in new issues. Thanks again for all the awesome feedback! It's helped make this library much more useful. |
As requested, from my thread on twitter, and a few more I just ran into.
The API is kind of confusing to me, in particular:
Lack of proper little-endian support, which was partially removed?This also plays into my confusion, theresUuid::(to/from)_fields_le
andUuid::(to/from)_u128_le
, but notUuid::from_bytes_le
? TheresUuid::as_bytes
but notUuid::as_bytes_le
?This in particular is complicating things for me, as the Uuids I want to handle are "inspired" by Microsoft and stored mixed-endian. (Also, something I encountered when switching the bytes myself isUuid::get_version_num
returning14
instead of4
, so those specific last few bits may need special handling?)See #462
The crate supports no_std, but theUuid
type isn't FFI safe/repr(transparent)
? There doesn't seem to be any reason for it not to be. That attribute is stable since 1.28.0, which is below the crates MSRV.See #463
API naming is kind of weird and inconsistent,Uuid
isCopy
butUuid::as_bytes
exists? Why notUuid::into_bytes
, theres noUuid::as_mut_bytes
anyway? This also matches the Rust API Guidelines C-CONV.See #465
The
(from/to/as?)_u128
api is confusing, becauseUuid
s aren'tu128
s at all! If someone has a u128 they want to make a Uuid, they can always extract a byte slice from it and useUuid::from_bytes(_le)
? Though, granted, the std methods to go from integers to bytes weren't stabilized until 1.32.0, which is one version above the MSRV. (Also the documented MSRV is 1.31.0 but travis CI is pinned to 1.32.0, even for 0.8.1?)Uuid::get_version
andUuid::get_version_num
are kind of confusing?, especially since the latters documentation says only V4 is supported? I think it'd be better ifUuid::get_version
returned justVersion
, and insteadVersion
had aUnknown(usize)
variant, though that might technically make adding a new recognized version would be breaking, since it wouldn't matchUnknown(usize)
anymore?It's unclear to me why all the
to_*_ref
APIs exist, given thatUuid
isCopy
?Most of the methods returning
Result
probably.. shouldnt?from_slice
probably doesn't need to exist anymore if you're going to be handling #457, as there are impls for arrays up to length 32 in std, so it can be replaced withUuid::from_bytes(slice.try_into().unwrap())
from_fields(_le)
should either take a fixed-size array, same reason as above.new_v1
should take an array, same reasons as above. Then it doesn't need aResult
, as that andfrom_fields(_le)
are the only reason it does.from_guid
even without any of the above shouldn't leak aResult
? GUID::Data4 is an array, so thefrom_fields_le
call can never be an error?Just ran into this one, but
Uuid::new_v4
says it uses therand
crates default RNG, and that you can useRand
trait if you need a custom generator, but there doesn't actually seem to be a way to giveUuid
your own random bytes? Something likewith_v4_random
?On that note, my crate is no_std and i'd like to use V4 Uuids, so
new_v4
should probably be gated on thestd
feature, andwith_v4_random
not.Speaking of v4, naming: Would it perhaps make more sense forUuid::nil
to be renamedUuid::new
and thenew_vX
methods renamed towith_vX
? I think that'd make more sense and be more inline with the Rust API Guidelines?Also,
Default
is manually implemented but it could be derived? Fixed size arrays(under length 32) implementDefault
, and Uuid/[u8; 16]
fit the bill.Also, the MSRV should probably be mentioned in the README more explicitly. The badge is easy to miss, and I did miss it at first.See #464
Sorry for the long issue and if it seems like i'm bashing the library :( just what I struggled with when using the library, and apologies if some of these have been addressed on the master branch?
The text was updated successfully, but these errors were encountered: