kinode_process_lib

Function make_blob

source
pub fn make_blob<T, F, E>(blob: &T, serializer: F) -> Result<LazyLoadBlob, E>
where F: Fn(&T) -> Result<Vec<u8>, E>, E: Error,
Expand description

Create a blob with no MIME type and a generic type, plus a serializer function that turns that type into bytes.

Example usage:

use kinode_process_lib::make_blob;
use bincode;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct MyType {
   field: std::collections::HashMap<String, String>,
   field_two: std::collections::HashSet<String>,
}

let my_type = MyType {
   field: std::collections::HashMap::new(),
   field_two: std::collections::HashSet::new(),
};

make_blob(&my_type, |t| Ok(bincode::serialize(t)?));