Into

Struct Into 

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

Adapter to serialize using a From conversion

This adapter works by converting to T and then serializing the converted value using adapter F.

§Example

use serde::Serialize;
use serde_json::json;

#[derive(Serialize)]
struct Foo(#[serde(with = "serdapt::Into::<u8>")] bool);

let v = serde_json::to_value(Foo(true)).unwrap();
assert_eq!(v, json!(1));

Implementations§

Source§

impl<T, F> Into<T, F>

Source

pub fn serialize<U, S>(value: &U, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer, Self: SerializeWith<U>,

Serializes value with adapter

Trait Implementations§

Source§

impl<T, U, F> SerializeWith<U> for Into<T, F>
where T: From<U>, U: Clone, F: SerializeWith<T>,

Source§

fn serialize_with<S: Serializer>( value: &U, serializer: S, ) -> Result<S::Ok, S::Error>

Serializes value using serializer

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T, F> UnwindSafe for Into<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.