pub fn from_slice<'a, T>(v: &'a [u8]) -> Result<T>where
T: Deserialize<'a>,Expand description
Deserialize an instance of type T from bytes of EnCom text.
§Example
use serde::Deserialize;
#[derive(Deserialize, Debug)]
struct User {
fingerprint: String,
location: String,
}
fn main() {
// The type of `j` is `&[u8]`
let j = b"
fingerprint:18=0xF9BA143B95FF6D82
location:14=Menlo Park, CA
";
let u: User = serde_encom::from_slice(j).unwrap();
println!("{:#?}", u);
}§Errors
This conversion can fail if the structure of the input does not match the
structure expected by T, for example if T is a struct type but the input
contains something other than an EnCom map. It can also fail if the structure
is correct but T’s implementation of Deserialize decides that something
is wrong with the data, for example required struct fields are missing from
the EnCom map or some number is too big to fit in the expected primitive
type.