Serialises UUID as [u8:16] #331
No reviewers
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid!331
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/dense_serde"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm submitting a feature
Description
Adds the ability to serialize a Uuid as a [u8; 16]. Functionality is behind the
dense_serdefeature. theserdefeature continues to serialize as a &[u8]. Both features serialize strings identicallyTests
A new test module for the feature was added, mirroring the tests of the
serdefeature (with modifications to expected tokens where necessary)Related Issue(s)
closes #329
Thanks @Redrield!
From the discussion on #329, using a feature flag here doesn't actually save us from potential breakage. It looks like we want to keep the output of
serdethe same for anyone that's currently depending on it.One way we could do this in a backwards compatible way that users properly opt into would be to convert your new
SerializeandDeserializeimpls into free functions, that can be used with the#[serde(serialize_with)]and#[serde(deserialize_with)]attributes.@KodrAus newtypes?
@kinggoesgaming I think a newtype isn't a natural solution here. It's really the same type, just serialized in a different way, and it may even depend on the context what serialization to use. I like the suggestion to use free functions for use with serde attributes, since it makes the intention of client code immediately obvious.
I'm thinking add a module that can be used with
#[serde(with = "uuid::dense_serde")]. (I'm not sure about the name, just an example)What do you think of
uuid::serde::compact? That way we've got aserdemodule too that any otherserdespecific stuff can live in?note
uuid::serdenamespace can't be used because it conflicts withserdecrateOk, so we could do
uuid::adapter::compact, oruuid::adapter::denseinstead ?Rewritten to use serde attributes for dense serialization under uuid::adapter::compact
@ -0,0 +1,117 @@//! Module for use with `#[serde(with = "...")]` to serialize a [`Uuid`]uhmm?
@ -0,0 +33,4 @@pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D,) -> Result<Uuid, D::Error> {struct DenseUuidBytesVisitor;do we need the struct inside of the function? Generally not a fan of this.
@ -0,0 +1,117 @@//! Module for use with `#[serde(with = "...")]` to serialize a [`Uuid`]Debug messages, i'll take those out, whoops!
@ -0,0 +33,4 @@pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D,) -> Result<Uuid, D::Error> {struct DenseUuidBytesVisitor;I was following in the pattern of the String visitors in the Deserialize impl in serde_support.rs, it can be moved if you prefer
@ -0,0 +33,4 @@pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D,) -> Result<Uuid, D::Error> {struct DenseUuidBytesVisitor;It is fine. Just something I don't like personally but i'm okay with it if it keeps it consistent with other impls in the crate
@ -0,0 +1,117 @@//! Module for use with `#[serde(with = "...")]` to serialize a [`Uuid`]add a // TODO just to be sure :)
we have a bot that marks TODO comments
@ -0,0 +1,117 @@//! Module for use with `#[serde(with = "...")]` to serialize a [`Uuid`]wdym? Removed them in
b1b2efebors r+
Build succeeded
@ -0,0 +33,4 @@pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D,) -> Result<Uuid, D::Error> {struct DenseUuidBytesVisitor;Huuuuuuggggeee necro...
It just keeps it very much contained and prevents any accidental use outside the function