Trait mbon::object::ObjectParse
source · pub trait ObjectParsewhere
Self: Sized,{
type Error;
fn parse_object(object: &[u8]) -> Result<Self, Self::Error>;
}
Expand description
A loader that can load a struct from a binary object.
A possible use case is to store a struct more efficiently than a map
use mbon::object::ObjectParse;
use mbon::parser::Parser;
use mbon::error::Error;
struct Foo {
a: u32,
b: String,
}
impl ObjectParse for Foo {
type Error = Error;
fn parse_object(object: &[u8]) -> Result<Self, Self::Error> {
let mut parser = Parser::from(object);
let a = parser.next()?;
let b = parser.next()?;
Ok(Self { a, b })
}
}
Required Associated Types
Required Methods
sourcefn parse_object(object: &[u8]) -> Result<Self, Self::Error>
fn parse_object(object: &[u8]) -> Result<Self, Self::Error>
Load from a binary object
This will parse the given object in a predefined format.