MaybeSerde

Struct MaybeSerde 

Source
pub struct MaybeSerde<T>(pub Option<T>);
Expand description

Helper type for connect serde and maybe-serde

This type implement both serde::{Serialize, Deserialize} for all T

It’s just helper type and not necessary

you could define your own type using MaybeSer and MaybeDe

§When Serialize

if T: Serialize and Option is Some then just serialize T itself (doesn’t serialize as Option!)

and T: !Serialize or Option is None then serialize None

maybe #[serde(skip_serializing_if = "T::IMPL_SERIALIZE")] attribute could be help

§When Deserialize

if T: Deserialize then get Some

and T: !Deserialize just None

Tuple Fields§

§0: Option<T>

Trait Implementations§

Source§

impl<'de, T: MaybeDe<'de>> Deserialize<'de> for MaybeSerde<T>

Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Into<Option<T>> for MaybeSerde<T>

Source§

fn into(self) -> Option<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T: MaybeSer> Serialize for MaybeSerde<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for MaybeSerde<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for MaybeSerde<T>
where T: RefUnwindSafe,

§

impl<T> Send for MaybeSerde<T>
where T: Send,

§

impl<T> Sync for MaybeSerde<T>
where T: Sync,

§

impl<T> Unpin for MaybeSerde<T>
where T: Unpin,

§

impl<T> UnwindSafe for MaybeSerde<T>
where T: 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<'de, T> MaybeDe<'de> for T

Source§

const IMPL_DESERIALIZE: bool = false

Always return false

Source§

default fn maybe_deserialize<D>( _deserializer: D, ) -> Option<Result<T, <D as Deserializer<'de>>::Error>>
where D: Deserializer<'de>,

Source§

impl<'de, T> MaybeDe<'de> for T
where T: Deserialize<'de>,

Source§

const IMPL_DESERIALIZE: bool = true

Always return true

Source§

fn maybe_deserialize<D>( deserializer: D, ) -> Option<Result<T, <D as Deserializer<'de>>::Error>>
where D: Deserializer<'de>,

Source§

impl<T> MaybeSer for T

Source§

const IMPL_SERIALIZE: bool = false

Always return false

Source§

default fn maybe_serialize<S>( &self, _serializer: S, ) -> Option<Result<<S as Serializer>::Ok, <S as Serializer>::Error>>
where S: Serializer,

Source§

impl<T> MaybeSer for T
where T: Serialize,

Source§

const IMPL_SERIALIZE: bool = true

Always return true

Source§

fn maybe_serialize<S>( &self, serializer: S, ) -> Option<Result<<S as Serializer>::Ok, <S as Serializer>::Error>>
where S: Serializer,

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,