Crate bytekind

source ·
Expand description

Containers for bytes that encode their serialization format as generics

let json = serde_json::json!([1, 2, 3, 4]);
let bytes: Bytes<Plain> = serde_json::from_value(json).unwrap();
assert_eq!(&bytes, &[1, 2, 3, 4]);

let bytes: Bytes<HexString> = bytes.convert();
let hex_string = serde_json::to_string(&bytes).unwrap();
assert_eq!(hex_string, "\"01020304\"");

Structs

  • A wrapper around [u8; N] that allows control over the serialization format
  • A wrapper around Vec<u8> that allows control over the serialization format
  • Format bytes as a hex string
  • Format bytes as plain bytes (i.e. what you’d get if you just derive(Serialize))

Traits

  • Types which represent a serialization format