Trait TryFromJson

Source
pub trait TryFromJson: Sized {
    type Error;

    // Required method
    fn try_from_json_at(
        value: &Value,
        code_map: &CodeMap,
        offset: usize,
    ) -> Result<Self, Self::Error>;

    // Provided method
    fn try_from_json(
        value: &Value,
        code_map: &CodeMap,
    ) -> Result<Self, Self::Error> { ... }
}
Expand description

Conversion from JSON syntax, with code mapping info.

This trait is very similar to TryFrom<Value> but also passes code code mapping info to the conversion function.

Required Associated Types§

Source

type Error

Error that may be returned by the conversion function.

Required Methods§

Source

fn try_from_json_at( value: &Value, code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Tries to convert the given JSON value into Self, using the given code_map and the offset of value in the code map.

Note to implementors: use the JsonArray::iter_mapped and Object::iter_mapped methods to visit arrays and objects while keeping track of the code map offset of each visited item.

Provided Methods§

Source

fn try_from_json(value: &Value, code_map: &CodeMap) -> Result<Self, Self::Error>

Tries to convert the given JSON value into Self, using the given code_map.

It is assumed that the offset of value in the code map is 0, for instance if it is the output of a Parse trait function.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TryFromJson for bool

Source§

type Error = Mapped<Unexpected>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for f32

Source§

type Error = Mapped<TryIntoNumberError<NumberType<f32>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for f64

Source§

type Error = Mapped<TryIntoNumberError<NumberType<f64>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for i8

Source§

type Error = Mapped<TryIntoNumberError<NumberType<i8>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for i16

Source§

type Error = Mapped<TryIntoNumberError<NumberType<i16>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for i32

Source§

type Error = Mapped<TryIntoNumberError<NumberType<i32>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for i64

Source§

type Error = Mapped<TryIntoNumberError<NumberType<i64>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for isize

Source§

type Error = Mapped<TryIntoNumberError<NumberType<isize>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for u8

Source§

type Error = Mapped<TryIntoNumberError<NumberType<u8>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for u16

Source§

type Error = Mapped<TryIntoNumberError<NumberType<u16>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for u32

Source§

type Error = Mapped<TryIntoNumberError<NumberType<u32>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for u64

Source§

type Error = Mapped<TryIntoNumberError<NumberType<u64>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for ()

Source§

type Error = Mapped<Unexpected>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for usize

Source§

type Error = Mapped<TryIntoNumberError<NumberType<usize>>>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl TryFromJson for String

Source§

type Error = Mapped<Unexpected>

Source§

fn try_from_json_at( json: &Value, _code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl<K: FromStr + Ord, V: TryFromJson> TryFromJson for BTreeMap<K, V>
where V::Error: From<Mapped<Unexpected>> + From<Mapped<K::Err>>,

Source§

type Error = <V as TryFromJson>::Error

Source§

fn try_from_json_at( json: &Value, code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl<T: TryFromJson> TryFromJson for Option<T>

Source§

type Error = <T as TryFromJson>::Error

Source§

fn try_from_json_at( json: &Value, code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl<T: TryFromJson> TryFromJson for Box<T>

Source§

type Error = <T as TryFromJson>::Error

Source§

fn try_from_json_at( json: &Value, code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Source§

impl<T: TryFromJson> TryFromJson for Vec<T>

Source§

type Error = <T as TryFromJson>::Error

Source§

fn try_from_json_at( json: &Value, code_map: &CodeMap, offset: usize, ) -> Result<Self, Self::Error>

Implementors§