Skip to main content

PhantomDeserData

Struct PhantomDeserData 

Source
pub struct PhantomDeserData<T: ?Sized>(pub PhantomData<T>);
Expand description

A type semantically equivalent to PhantomData, but whose type parameter is replaced with its associated deserialization type.

In some case, you might find yourself with a deep-copy type that has a type parameter T appearing both in a field and in a PhantomData. In this case, the type will not compile, as in its associated deserialization type T will be replaced by T::DeserType, but the PhantomData field will still contain T. To fix this issue, you can use PhantomDeserData instead.

Note that T must be sized.

§Examples

This code will not compile:

use epserde::prelude::*;
#[derive(Epserde, Debug, PartialEq, Eq, Clone, Default)]
struct Data<T> {
    data: T,
    phantom: PhantomData<T>,
}

This code, instead, will compile:

use epserde::prelude::*;
#[derive(Epserde, Debug, PartialEq, Eq, Clone, Default)]
struct Data<T> {
    data: T,
    phantom: PhantomDeserData<T>,
}

Tuple Fields§

§0: PhantomData<T>

Implementations§

Source§

impl<T: DeserInner> PhantomDeserData<T>

Source

pub unsafe fn _deser_eps_inner_special<'a>( _backend: &mut SliceWithPos<'a>, ) -> Result<PhantomDeserData<T::DeserType<'a>>>

A custom deserialization method for PhantomDeserData that transmutes the inner type.

§Safety

See DeserInner::_deser_eps_inner.

Trait Implementations§

Source§

impl<T> AlignHash for PhantomDeserData<T>

Source§

fn align_hash(_hasher: &mut impl Hasher, _offset_of: &mut usize)

Accumulates alignment information in hasher assuming to be positioned at offset_of.
Source§

fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)

Calls AlignHash::align_hash on a value.
Source§

impl<T> AlignTo for PhantomDeserData<T>

Source§

impl<T: Clone + ?Sized> Clone for PhantomDeserData<T>

Source§

fn clone(&self) -> PhantomDeserData<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> CopyType for PhantomDeserData<T>

Source§

impl<T: Debug + ?Sized> Debug for PhantomDeserData<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + ?Sized> Default for PhantomDeserData<T>

Source§

fn default() -> PhantomDeserData<T>

Returns the “default value” for a type. Read more
Source§

impl<T: DeserInner> DeserInner for PhantomDeserData<T>

Source§

type DeserType<'a> = PhantomDeserData<<T as DeserInner>::DeserType<'a>>

The deserialization type associated with this type. It can be retrieved conveniently with the alias DeserType.
Source§

unsafe fn _deser_full_inner(_backend: &mut impl ReadWithPos) -> Result<Self>

Safety Read more
Source§

unsafe fn _deser_eps_inner<'a>( _backend: &mut SliceWithPos<'a>, ) -> Result<Self::DeserType<'a>>

Safety Read more
Source§

impl<T: Hash + ?Sized> Hash for PhantomDeserData<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq + ?Sized> PartialEq for PhantomDeserData<T>

Source§

fn eq(&self, other: &PhantomDeserData<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> SerInner for PhantomDeserData<T>

Source§

const IS_ZERO_COPY: bool = true

Inner constant used by the derive macros to keep track recursively of whether the type satisfies the conditions for being zero-copy. It is checked at runtime against the trait implemented by the type, and if a ZeroCopy type has this constant set to false serialization will panic.
Source§

type SerType = PhantomDeserData<T>

This is the type that will be written in the header of the file, and thus the type that will be deserialized. In most cases it is Self, but in some cases, as for references to slices, it is customized.
Source§

unsafe fn _ser_inner(&self, _backend: &mut impl WriteWithNames) -> Result<()>

Serializes this structure using the given backend. Read more
Source§

impl<T: TypeHash> TypeHash for PhantomDeserData<T>

Source§

fn type_hash(hasher: &mut impl Hasher)

Accumulates type information in hasher.
Source§

fn type_hash_val(&self, hasher: &mut impl Hasher)

Calls TypeHash::type_hash on a value.
Source§

impl<T: Copy + ?Sized> Copy for PhantomDeserData<T>

Source§

impl<T: Eq + ?Sized> Eq for PhantomDeserData<T>

Source§

impl<T: ?Sized> StructuralPartialEq for PhantomDeserData<T>

Auto Trait Implementations§

§

impl<T> Freeze for PhantomDeserData<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for PhantomDeserData<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for PhantomDeserData<T>
where T: Send + ?Sized,

§

impl<T> Sync for PhantomDeserData<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for PhantomDeserData<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for PhantomDeserData<T>
where T: UnwindSafe + ?Sized,

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> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<T> ZeroCopy for T
where T: Copy + SerInner<SerType = T> + CopyType<Copy = Zero> + DeserInner + TypeHash + AlignHash + AlignTo + 'static,