pub fn from_element<T: DeserializeOwned>(
attributes: &[Attribute],
text: Option<&str>,
) -> Result<T>Available on crate feature
serde only.Expand description
Deserializes T from an element’s attributes and optional text.
Useful when an Event::StartTag is already at
hand. Child elements are not available here: use
AbxParser::deserialize_next for types
with child-element fields.
§Errors
Returns AbxError::Deserialization if the attributes do not match T.
§Examples
use android_abx::{Attribute, AttributeValue};
use serde::Deserialize;
#[derive(Deserialize)]
struct Pkg {
name: String,
version: Option<u32>,
}
let attributes = [Attribute {
name: "name".into(),
value: AttributeValue::String("com.example".into()),
}];
let pkg: Pkg = android_abx::from_element(&attributes, None)?;
assert_eq!(pkg.name, "com.example");
assert_eq!(pkg.version, None);