pub fn serialize_with_flavor<T, S, O>(value: &T, storage: S) -> Result<O>where
    T: Serialize + ?Sized,
    S: Flavor<Output = O>,
Expand description

serialize_with_flavor() has three generic parameters, T, F, O.

  • T: This is the type that is being serialized
  • S: This is the Storage that is used during serialization
  • O: This is the resulting storage type that is returned containing the serialized data

For more information about how Flavors work, please see the flavors module documentation.

use postcard::{
    ser_flavors::{Cobs, Slice},

let mut buf = [0u8; 32];

let data: &[u8] = &[0x01, 0x00, 0x20, 0x30];
let buffer = &mut [0u8; 32];
let res = serialize_with_flavor::<[u8], Cobs<Slice>, &mut [u8]>(

assert_eq!(res, &[0x03, 0x04, 0x01, 0x03, 0x20, 0x30, 0x00]);