pub trait SerHexSeq<C>:
Sized
+ SerHex<Strict>
+ SerHex<StrictCap>where
C: HexConf,{
// Required method
fn size() -> usize;
// Provided methods
fn serialize<'a, S, T>(
sequence: T,
serializer: S,
) -> Result<S::Ok, S::Error>
where S: Serializer,
T: IntoIterator<Item = &'a Self>,
Self: 'a { ... }
fn deserialize<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where D: Deserializer<'de>,
T: FromIterator<Self> { ... }
}
Expand description
Variant of SerHex
for serializing/deserializing sequence types as
contiguous hexadecimal strings.
NOTE: Compact
configurations are not compatible with this trait.
The size of each element must be consistent in order to avoid ambiguous
encoding.
#[derive(Debug,PartialEq,Eq,Serialize,Deserialize)]
struct Bytes(#[serde(with = "SerHexSeq::<StrictPfx>")] Vec<u8>);
let bytes: Bytes = serde_json::from_str(r#""0xdeadbeef""#).unwrap();
assert_eq!(bytes,Bytes(vec![0xde,0xad,0xbe,0xef]));
Required Methods§
Provided Methods§
Sourcefn serialize<'a, S, T>(sequence: T, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
T: IntoIterator<Item = &'a Self>,
Self: 'a,
fn serialize<'a, S, T>(sequence: T, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
T: IntoIterator<Item = &'a Self>,
Self: 'a,
Same as SerHex::serialize
, but for sequences of Self
.
Sourcefn deserialize<'de, D, T>(deserializer: D) -> Result<T, D::Error>where
D: Deserializer<'de>,
T: FromIterator<Self>,
fn deserialize<'de, D, T>(deserializer: D) -> Result<T, D::Error>where
D: Deserializer<'de>,
T: FromIterator<Self>,
Same as SerHex::deserialize
, but for sequences of Self
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.