PeekEnum

Struct PeekEnum 

Source
pub struct PeekEnum<'mem, 'facet> { /* private fields */ }
Available on crate feature reflect only.
Expand description

Lets you read from an enum (implements read-only enum operations)

Implementations§

Source§

impl<'mem, 'facet> PeekEnum<'mem, 'facet>

Source

pub fn ty(self) -> EnumType

Returns the enum definition

Source

pub fn enum_repr(self) -> EnumRepr

Returns the enum representation

Source

pub fn variants(self) -> &'static [Variant]

Returns the enum variants

Source

pub fn variant_count(self) -> usize

Returns the number of variants in this enum

Source

pub fn variant_name(self, index: usize) -> Option<&'static str>

Returns the variant name at the given index

Source

pub fn discriminant(self) -> i64

Returns the discriminant value for the current enum value

Note: For RustNPO (null pointer optimization) types, there is no explicit discriminant stored in memory. In this case, 0 is returned. Use variant_index() to determine the active variant for NPO types.

Source

pub fn variant_index(self) -> Result<usize, VariantError>

Returns the variant index for this enum value

Source

pub fn active_variant(self) -> Result<&'static Variant, VariantError>

Returns the active variant

Source

pub fn variant_name_active(self) -> Result<&'static str, VariantError>

Returns the name of the active variant for this enum value

Source

pub fn field( self, index: usize, ) -> Result<Option<Peek<'mem, 'facet>>, VariantError>

Returns a PeekValue handle to a field of a tuple or struct variant by index

Source

pub fn field_index( self, field_name: &str, ) -> Result<Option<usize>, VariantError>

Returns the index of a field in the active variant by name

Source

pub fn field_by_name( self, field_name: &str, ) -> Result<Option<Peek<'mem, 'facet>>, VariantError>

Returns a PeekValue handle to a field of a tuple or struct variant by name

Methods from Deref<Target = Peek<'mem, 'facet>>§

Source

pub fn variance(&self) -> Variance

Returns the computed variance of the underlying type.

This walks the type’s fields to determine if the type is covariant, contravariant, or invariant over its lifetime parameter.

Source

pub fn vtable(&self) -> VTableErased

Returns the vtable

Source

pub fn id(&self) -> ValueId

Returns a unique identifier for this value, usable for cycle detection

Source

pub fn ptr_eq(&self, other: &Peek<'_, '_>) -> bool

Returns true if the two values are pointer-equal

Source

pub fn partial_eq(&self, other: &Peek<'_, '_>) -> Result<bool, ReflectError>

Returns true if this scalar is equal to the other scalar

§Returns

false if equality comparison is not supported for this scalar type

Source

pub fn partial_cmp( &self, other: &Peek<'_, '_>, ) -> Result<Option<Ordering>, ReflectError>

Compares this scalar with another and returns their ordering

§Returns

None if comparison is not supported for this scalar type

Source

pub fn hash(&self, hasher: &mut dyn Hasher) -> Result<(), ReflectError>

Hashes this scalar using the vtable hash function.

§Returns

Err if hashing is not supported for this scalar type, Ok otherwise

Source

pub fn structural_hash<H>(&self, hasher: &mut H)
where H: Hasher,

Computes a structural hash of this value.

Unlike hash, this method recursively traverses the structure and hashes each component, making it work for types that don’t implement Hash.

For scalars with a vtable hash function, it uses that. For compound types (structs, enums, lists, etc.), it recursively hashes the structure.

This is useful for Merkle-tree style hashing where you want to compare subtrees for equality based on their structural content.

Source

pub fn type_name( &self, f: &mut Formatter<'_>, opts: TypeNameOpts, ) -> Result<(), Error>

Returns the type name of this scalar

§Arguments
  • f - A mutable reference to a core::fmt::Formatter
  • opts - The TypeNameOpts to use for formatting
§Returns

The result of the type name formatting

Source

pub fn shape(&self) -> &'static Shape

Returns the shape

Source

pub fn data(&self) -> PtrConst

Returns the data

Source

pub fn scalar_type(&self) -> Option<ScalarType>

Get the scalar type if set.

Source

pub fn get<T>(&self) -> Result<&'mem T, ReflectError>
where T: Facet<'facet> + ?Sized,

Read the value from memory into a Rust value.

§Panics

Panics if the shape doesn’t match the type T.

Source

pub fn as_str(&self) -> Option<&'mem str>

Try to get the value as a string if it’s a string type Returns None if the value is not a string or couldn’t be extracted

Source

pub fn as_bytes(&self) -> Option<&'mem [u8]>

Try to get the value as a byte slice if it’s a &u8 type Returns None if the value is not a byte slice or couldn’t be extracted

Source

pub fn custom_serialization( &self, field: Field, ) -> Result<OwnedPeek<'mem>, ReflectError>

Available on crate feature alloc only.

Performs custom serialization of the current peek using the provided field’s metadata.

Returns an OwnedPeek that points to the final type that should be serialized in place of the current peek.

Source

pub fn custom_serialization_from_shape( &self, ) -> Result<Option<OwnedPeek<'mem>>, ReflectError>

Available on crate feature alloc only.

Returns an OwnedPeek using the shape’s container-level proxy for serialization.

This is used when a type has #[facet(proxy = ProxyType)] at the container level. Unlike field-level proxies which are checked via custom_serialization(field), this method checks the Shape itself for a proxy definition.

Returns None if the shape has no container-level proxy.

Trait Implementations§

Source§

impl<'mem, 'facet> Clone for PeekEnum<'mem, 'facet>

Source§

fn clone(&self) -> PeekEnum<'mem, 'facet>

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 Debug for PeekEnum<'_, '_>

Source§

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

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

impl<'mem, 'facet> Deref for PeekEnum<'mem, 'facet>

Source§

type Target = Peek<'mem, 'facet>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<PeekEnum<'mem, 'facet> as Deref>::Target

Dereferences the value.
Source§

impl<'mem, 'facet> HasFields<'mem, 'facet> for PeekEnum<'mem, 'facet>

Source§

fn fields(&self) -> FieldIter<'mem, 'facet>

Iterates over all fields in this type, providing both field metadata and value
Source§

fn fields_for_serialize(&self) -> FieldsForSerializeIter<'mem, 'facet>

Iterates over fields in this type that should be included when it is serialized
Source§

impl<'mem, 'facet> Copy for PeekEnum<'mem, 'facet>

Auto Trait Implementations§

§

impl<'mem, 'facet> Freeze for PeekEnum<'mem, 'facet>

§

impl<'mem, 'facet> RefUnwindSafe for PeekEnum<'mem, 'facet>

§

impl<'mem, 'facet> !Send for PeekEnum<'mem, 'facet>

§

impl<'mem, 'facet> !Sync for PeekEnum<'mem, 'facet>

§

impl<'mem, 'facet> Unpin for PeekEnum<'mem, 'facet>

§

impl<'mem, 'facet> UnwindSafe for PeekEnum<'mem, 'facet>

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> 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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.