pub struct PeekEnum<'mem, 'facet> { /* private fields */ }reflect only.Expand description
Lets you read from an enum (implements read-only enum operations)
Implementations§
Source§impl<'mem, 'facet> PeekEnum<'mem, 'facet>
impl<'mem, 'facet> PeekEnum<'mem, 'facet>
Sourcepub fn variant_count(self) -> usize
pub fn variant_count(self) -> usize
Returns the number of variants in this enum
Sourcepub fn variant_name(self, index: usize) -> Option<&'static str>
pub fn variant_name(self, index: usize) -> Option<&'static str>
Returns the variant name at the given index
Sourcepub fn discriminant(self) -> i64
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.
Sourcepub fn variant_index(self) -> Result<usize, VariantError>
pub fn variant_index(self) -> Result<usize, VariantError>
Returns the variant index for this enum value
Sourcepub fn active_variant(self) -> Result<&'static Variant, VariantError>
pub fn active_variant(self) -> Result<&'static Variant, VariantError>
Returns the active variant
Sourcepub fn variant_name_active(self) -> Result<&'static str, VariantError>
pub fn variant_name_active(self) -> Result<&'static str, VariantError>
Returns the name of the active variant for this enum value
Sourcepub fn field(
self,
index: usize,
) -> Result<Option<Peek<'mem, 'facet>>, VariantError>
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
Sourcepub fn field_index(
self,
field_name: &str,
) -> Result<Option<usize>, VariantError>
pub fn field_index( self, field_name: &str, ) -> Result<Option<usize>, VariantError>
Returns the index of a field in the active variant by name
Sourcepub fn field_by_name(
self,
field_name: &str,
) -> Result<Option<Peek<'mem, 'facet>>, VariantError>
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>>§
Sourcepub fn variance(&self) -> Variance
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.
Sourcepub fn vtable(&self) -> VTableErased
pub fn vtable(&self) -> VTableErased
Returns the vtable
Sourcepub fn id(&self) -> ValueId
pub fn id(&self) -> ValueId
Returns a unique identifier for this value, usable for cycle detection
Sourcepub fn ptr_eq(&self, other: &Peek<'_, '_>) -> bool
pub fn ptr_eq(&self, other: &Peek<'_, '_>) -> bool
Returns true if the two values are pointer-equal
Sourcepub fn partial_eq(&self, other: &Peek<'_, '_>) -> Result<bool, ReflectError>
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
Sourcepub fn partial_cmp(
&self,
other: &Peek<'_, '_>,
) -> Result<Option<Ordering>, ReflectError>
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
Sourcepub fn hash(&self, hasher: &mut dyn Hasher) -> Result<(), ReflectError>
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
Sourcepub fn structural_hash<H>(&self, hasher: &mut H)where
H: Hasher,
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.
Sourcepub fn scalar_type(&self) -> Option<ScalarType>
pub fn scalar_type(&self) -> Option<ScalarType>
Get the scalar type if set.
Sourcepub fn get<T>(&self) -> Result<&'mem T, ReflectError>
pub fn get<T>(&self) -> Result<&'mem T, ReflectError>
Sourcepub fn as_str(&self) -> Option<&'mem str>
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
Sourcepub fn as_bytes(&self) -> Option<&'mem [u8]>
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
Sourcepub fn custom_serialization(
&self,
field: Field,
) -> Result<OwnedPeek<'mem>, ReflectError>
Available on crate feature alloc only.
pub fn custom_serialization( &self, field: Field, ) -> Result<OwnedPeek<'mem>, ReflectError>
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.
Sourcepub fn custom_serialization_from_shape(
&self,
) -> Result<Option<OwnedPeek<'mem>>, ReflectError>
Available on crate feature alloc only.
pub fn custom_serialization_from_shape( &self, ) -> Result<Option<OwnedPeek<'mem>>, ReflectError>
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.