pub struct SerializedBytes(/* private fields */);
Expand description
A Canonical Serialized Bytes representation for data If you have a data structure that needs a canonical byte representation use this Always round-trip through SerializedBytes via. a single TryFrom implementation. This ensures that the internal bytes of SerializedBytes are indeed canonical. The corrolary is that if bytes are NOT wrapped in SerializedBytes we can assume they are NOT canonical. Typically we need a canonical serialization when data is to be handled at the byte level by independently implemented and maintained systems.
Examples of times we need a canonical set of bytes to represent data:
- cryptographic operations
- moving across the host/guest wasm boundary
- putting data on the network
Examples of times where we may not need a canonical representation and so may not need this:
- round tripping data through a database that has its own serialization preferences
- debug output or logging of data that is to be human readible
- moving between data types within a single system that has no external facing representation
uses #[repr(transparent)] to maximise compatibility with ffi @see https://doc.rust-lang.org/1.26.2/unstable-book/language-features/repr-transparent.html#enter-reprtransparent
uses serde_bytes for efficient serialization and deserialization without this every byte will be individually round tripped through serde @see https://crates.io/crates/serde_bytes
Implementations§
Trait Implementations§
source§impl Clone for SerializedBytes
impl Clone for SerializedBytes
source§fn clone(&self) -> SerializedBytes
fn clone(&self) -> SerializedBytes
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SerializedBytes
impl Debug for SerializedBytes
A bit of magic to convert the internal messagepack bytes into roughly equivalent JSON output for the purposes of debugging. 90% of the time you probably want this if you are a dev, to see something that “looks like” a data structure when you do {:?} in a formatted string, rather than a vector of bytes in the remaining 10% of situations where you want to debug the real messagepack bytes, call the .bytes() method on SerializedBytes and debug that.
source§impl Default for SerializedBytes
impl Default for SerializedBytes
source§impl<'de> Deserialize<'de> for SerializedBytes
impl<'de> Deserialize<'de> for SerializedBytes
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<SerializedBytes> for UnsafeBytes
impl From<SerializedBytes> for UnsafeBytes
source§fn from(sb: SerializedBytes) -> Self
fn from(sb: SerializedBytes) -> Self
source§impl From<UnsafeBytes> for SerializedBytes
impl From<UnsafeBytes> for SerializedBytes
source§fn from(b: UnsafeBytes) -> Self
fn from(b: UnsafeBytes) -> Self
source§impl Hash for SerializedBytes
impl Hash for SerializedBytes
source§impl Ord for SerializedBytes
impl Ord for SerializedBytes
source§fn cmp(&self, other: &SerializedBytes) -> Ordering
fn cmp(&self, other: &SerializedBytes) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for SerializedBytes
impl PartialEq for SerializedBytes
source§fn eq(&self, other: &SerializedBytes) -> bool
fn eq(&self, other: &SerializedBytes) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for SerializedBytes
impl PartialOrd for SerializedBytes
source§fn partial_cmp(&self, other: &SerializedBytes) -> Option<Ordering>
fn partial_cmp(&self, other: &SerializedBytes) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for SerializedBytes
impl Serialize for SerializedBytes
source§impl TryFrom<&()> for SerializedBytes
impl TryFrom<&()> for SerializedBytes
§type Error = SerializedBytesError
type Error = SerializedBytesError
source§fn try_from(t: &()) -> Result<SerializedBytes, SerializedBytesError>
fn try_from(t: &()) -> Result<SerializedBytes, SerializedBytesError>
source§impl<'a> TryFrom<&'a SerializedBytes> for SerializedBytes
impl<'a> TryFrom<&'a SerializedBytes> for SerializedBytes
§type Error = SerializedBytesError
type Error = SerializedBytesError
source§impl TryFrom<()> for SerializedBytes
impl TryFrom<()> for SerializedBytes
§type Error = SerializedBytesError
type Error = SerializedBytesError
source§fn try_from(t: ()) -> Result<SerializedBytes, SerializedBytesError>
fn try_from(t: ()) -> Result<SerializedBytes, SerializedBytesError>
source§impl TryFrom<SerializedBytes> for ()
impl TryFrom<SerializedBytes> for ()
§type Error = SerializedBytesError
type Error = SerializedBytesError
source§fn try_from(sb: SerializedBytes) -> Result<(), SerializedBytesError>
fn try_from(sb: SerializedBytes) -> Result<(), SerializedBytesError>
impl Eq for SerializedBytes
impl StructuralPartialEq for SerializedBytes
Auto Trait Implementations§
impl Freeze for SerializedBytes
impl RefUnwindSafe for SerializedBytes
impl Send for SerializedBytes
impl Sync for SerializedBytes
impl Unpin for SerializedBytes
impl UnwindSafe for SerializedBytes
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.