You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There have been many requests for supporting 3rd party crates such as: time, rust_decimal, uuid, and chrono. Rather than implementing support manually for these crates and more, an easier solution is to allow types implementing serde::Serialize inside types implementing bitcode::Encode.
This was previously a feature in 0.5, but we didn't reimplement it in the 0.6 rewrite due due to technical limitations. I have since found a path forward and intend to add this feature to 0.6.
The downsides of using serde instead of implementing these types in native bitcode are:
Worse performance
Requiring #[bitcode(with_serde)] annotations on every field where serde is used
Doesn't work well on collection types since it forces everything inside them to use serde
1 and 2 aren't much of an issue if serde is used infrequently. 3 poses more of an issue, but so far none of the types requested are collections. We could mitigate it by implementing some of the popular collections such as IndexMap.
Implementing this would partially-fully resolve these open issues: #45 could use serde_repr to serialize enum as u16 #40 #39 #38 #37 #35 bitcode serde already supports recursive types, so you could embed them in bitcode::Encode types #33 #29 use serde on field you want to skip with serialize impl that does nothing #27 #24 #13 #58
Reacted by Finn Bear, vnghia, cpprust, koxu1996 and LeoniePhiline
I would like to ask if we use #[bitcode(with_serde) for example with uuid::Uuid, do we get to choose which representation we want (something similar with {de}serialize_with) because I think most people will want to encode an Uuid with u128 instead of a str (no one will open the bitcode message to read anyway :D).
Activity
finnbear commentedon Sep 24, 2024
Downside 4:
serializereturns aResult, soencodewould either have to return aResult(breaks compatibility with0.6) or panic onErrfromserialize.Still in favor of this, though!
caibear commentedon Sep 24, 2024
Implementing this would partially-fully resolve these open issues:
#45 could use
serde_reprto serialize enum as u16#40
#39
#38
#37
#35 bitcode serde already supports recursive types, so you could embed them in
bitcode::Encodetypes#33
#29 use serde on field you want to skip with serialize impl that does nothing
#27
#24
#13
#58
vnghia commentedon Sep 25, 2024
I would like to ask if we use
#[bitcode(with_serde)for example withuuid::Uuid, do we get to choose which representation we want (something similar with{de}serialize_with) because I think most people will want to encode anUuidwithu128instead of astr(no one will open the bitcode message to read anyway :D).finnbear commentedon Sep 25, 2024
The correct choice is made automatically, considering
uuidchecks whether the format is human readable.bitcodeis not human readable, souuiduses raw bytes.