TryFrom

Struct TryFrom 

Source
pub struct TryFrom<T, F = Id> { /* private fields */ }
Expand description

Adapter to deserialize using a TryFrom conversion

This adapter works by deserializing a value of type T using adapter F, and then attempting a conversion from T to the target type.

§Example

use serde::Deserialize;
use serde_json::json;

#[derive(Deserialize)]
struct Foo(#[serde(with = "serdapt::TryFrom::<u32>")] char);

let x = serde_json::from_value::<Foo>(json!(b'a')).unwrap();
assert_eq!(x.0, 'a');

Implementations§

Source§

impl<T, F> TryFrom<T, F>

Source

pub fn deserialize<'de, U, D>(deserializer: D) -> Result<U, D::Error>
where D: Deserializer<'de>, Self: DeserializeWith<'de, U>,

Deserializes value with adapter

Trait Implementations§

Source§

impl<'de, T, U, F> DeserializeWith<'de, U> for TryFrom<T, F>
where U: TryFrom<T>, U::Error: Display, F: DeserializeWith<'de, T>,

Source§

fn deserialize_with<D>(deserializer: D) -> Result<U, D::Error>
where D: Deserializer<'de>,

Deserializes a value using deserializer

Auto Trait Implementations§

§

impl<T, F> Freeze for TryFrom<T, F>

§

impl<T, F> RefUnwindSafe for TryFrom<T, F>
where F: RefUnwindSafe,

§

impl<T, F> Send for TryFrom<T, F>
where F: Send,

§

impl<T, F> Sync for TryFrom<T, F>
where F: Sync,

§

impl<T, F> Unpin for TryFrom<T, F>
where F: Unpin,

§

impl<T, F> UnwindSafe for TryFrom<T, F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.