use crate::error::{Error, Result}; use serde_json::Value; /// Some extensions for serde_json::Value to be used as TDLib object pub trait ValueExt { /// get @type from json fn get_type<'a>(&'a self) -> Result<&'a str>; /// get @extra from json fn get_extra<'a>(&'a self) -> Result<&'a str>; } impl ValueExt for Value { fn get_type<'a>(&'a self) -> Result<&'a str> { self["@type"].as_str().ok_or(Error::HasNoTypeInJson) } fn get_extra<'a>(&'a self) -> Result<&'a str> { self["@extra"] .as_str() .ok_or_else(|| Error::InvalidJson("no @extra in json".into())) } }