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: DeserializeInner> PhantomDeserData<T>
impl<T: DeserializeInner> PhantomDeserData<T>
Sourcepub unsafe fn _deserialize_eps_inner_special<'a>(
_backend: &mut SliceWithPos<'a>,
) -> Result<PhantomDeserData<T::DeserType<'a>>>
pub unsafe fn _deserialize_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
Trait Implementations§
Source§impl<T: ?Sized> AlignHash for PhantomDeserData<T>
impl<T: ?Sized> AlignHash for PhantomDeserData<T>
Source§fn align_hash(_hasher: &mut impl Hasher, _offset_of: &mut usize)
fn align_hash(_hasher: &mut impl Hasher, _offset_of: &mut usize)
Accumulate 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)
fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)
Call
AlignHash::align_hash
on a value.Source§impl<T: Clone + ?Sized> Clone for PhantomDeserData<T>
impl<T: Clone + ?Sized> Clone for PhantomDeserData<T>
Source§fn clone(&self) -> PhantomDeserData<T>
fn clone(&self) -> PhantomDeserData<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T: Default + ?Sized> Default for PhantomDeserData<T>
impl<T: Default + ?Sized> Default for PhantomDeserData<T>
Source§fn default() -> PhantomDeserData<T>
fn default() -> PhantomDeserData<T>
Returns the “default value” for a type. Read more
Source§impl<T: DeserializeInner> DeserializeInner for PhantomDeserData<T>
impl<T: DeserializeInner> DeserializeInner for PhantomDeserData<T>
Source§type DeserType<'a> = PhantomDeserData<<T as DeserializeInner>::DeserType<'a>>
type DeserType<'a> = PhantomDeserData<<T as DeserializeInner>::DeserType<'a>>
The deserialization type associated with this type. It can be retrieved
conveniently with the alias
DeserType
.Source§unsafe fn _deserialize_full_inner(
_backend: &mut impl ReadWithPos,
) -> Result<Self>
unsafe fn _deserialize_full_inner( _backend: &mut impl ReadWithPos, ) -> Result<Self>
Safety Read more
Source§unsafe fn _deserialize_eps_inner<'a>(
_backend: &mut SliceWithPos<'a>,
) -> Result<Self::DeserType<'a>>
unsafe fn _deserialize_eps_inner<'a>( _backend: &mut SliceWithPos<'a>, ) -> Result<Self::DeserType<'a>>
Safety Read more
Source§impl<T: ?Sized> MaxSizeOf for PhantomDeserData<T>
impl<T: ?Sized> MaxSizeOf for PhantomDeserData<T>
fn max_size_of() -> usize
Source§impl<T: ?Sized> SerializeInner for PhantomDeserData<T>
impl<T: ?Sized> SerializeInner for PhantomDeserData<T>
Source§const IS_ZERO_COPY: bool = true
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§const ZERO_COPY_MISMATCH: bool = false
const ZERO_COPY_MISMATCH: bool = false
Inner constant used by the derive macros to keep
track of whether all fields of a type are zero-copy
but neither the attribute
#[zero_copy]
nor the attribute #[deep_copy]
was specified. It is checked at runtime, and if it is true
a warning will be issued, as the type could be zero-copy,
which would be more efficient.Source§type SerType = PhantomDeserData<T>
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 _serialize_inner(
&self,
_backend: &mut impl WriteWithNames,
) -> Result<()>
unsafe fn _serialize_inner( &self, _backend: &mut impl WriteWithNames, ) -> Result<()>
Serialize this structure using the given backend. Read more
Source§impl<T: ?Sized + TypeHash> TypeHash for PhantomDeserData<T>
impl<T: ?Sized + TypeHash> TypeHash for PhantomDeserData<T>
Source§fn type_hash_val(&self, hasher: &mut impl Hasher)
fn type_hash_val(&self, hasher: &mut impl Hasher)
Call
TypeHash::type_hash
on a value.impl<T: Copy + ?Sized> Copy for PhantomDeserData<T>
impl<T: Eq + ?Sized> Eq for PhantomDeserData<T>
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>
impl<T> Sync for PhantomDeserData<T>
impl<T> Unpin for PhantomDeserData<T>
impl<T> UnwindSafe for PhantomDeserData<T>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Deserialize for T
impl<T> Deserialize for T
Source§unsafe fn deserialize_full(backend: &mut impl ReadNoStd) -> Result<T, Error>
unsafe fn deserialize_full(backend: &mut impl ReadNoStd) -> Result<T, Error>
§Safety
See the documentation of Deserialize
.
Source§unsafe fn deserialize_eps(
backend: &[u8],
) -> Result<<T as DeserializeInner>::DeserType<'_>, Error>
unsafe fn deserialize_eps( backend: &[u8], ) -> Result<<T as DeserializeInner>::DeserType<'_>, Error>
§Safety
See the documentation of Deserialize
.
Source§unsafe fn load_full(path: impl AsRef<Path>) -> Result<Self>
unsafe fn load_full(path: impl AsRef<Path>) -> Result<Self>
Convenience method to fully deserialize from a file. Read more
Source§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
Source§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Truncate the current UnsignedInt to a possibly smaller size
Source§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
Source§impl<T> UpcastableFrom<T> for T
impl<T> UpcastableFrom<T> for T
Source§fn upcast_from(value: T) -> T
fn upcast_from(value: T) -> T
Extend the current UnsignedInt to a possibly bigger size.