Struct Shape

Source
pub struct Shape {
    pub name: NameFn,
    pub typeid: TypeId,
    pub layout: Layout,
    pub innards: Innards,
    pub set_to_default: Option<SetToDefaultFn>,
    pub drop_in_place: Option<DropFn>,
}
Expand description

Schema for reflection of a type

Fields§

§name: NameFn

A descriptive name for the type, e.g. u64, or Person

§typeid: TypeId

The typeid of the underlying type

§layout: Layout

Size, alignment

§innards: Innards

Details/contents of the value

§set_to_default: Option<SetToDefaultFn>

Set the value at a given address to the default value for this type

§drop_in_place: Option<DropFn>

Drop the value at a given address

§Safety

This function should be called only for initialized values. It’s the caller’s responsibility to ensure the address points to a valid value.

Implementations§

Source§

impl Shape

Source

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

Pretty-print this shape, recursively.

Source§

impl Shape

Source

pub unsafe fn get_scalar_contents<'a>( &self, ptr: *const u8, ) -> ScalarContents<'a>

Extract the scalar contents from a shape and a pointer

§Safety

This function is unsafe because it reads from raw memory. The caller must ensure that:

  1. The pointer points to a valid, initialized value of the correct type
  2. The memory is properly aligned for the type
  3. The memory is not mutated while the returned ScalarContents is in use
Source

pub fn known_fields(&self) -> &'static [Field]

Returns a slice of statically known fields. Fields that are not in there might still be inserted if it’s a dynamic collection.

Source

pub fn field_by_name(&self, name: &str) -> Option<&Field>

Returns a reference to a field with the given name, if it exists

Source

pub fn field_by_index(&self, index: usize) -> Result<&Field, FieldError>

Returns a reference to a field with the given index, if it exists

Source

pub fn dangling(&self) -> NonNull<u8>

Returns a dangling pointer for this shape.

This is useful for zero-sized types (ZSTs) which don’t need actual memory allocation, but still need a properly aligned “some address”.

§Safety

This function returns a dangling pointer. It should only be used in contexts where a non-null pointer is required but no actual memory access will occur, such as for ZSTs.

Source

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

Returns a slice of enum variants, if this shape represents an enum

Source

pub fn variant_by_name(&self, name: &str) -> Option<&Variant>

Returns a reference to a variant with the given name, if it exists

Source

pub fn variant_by_index(&self, index: usize) -> Result<&Variant, VariantError>

Returns a reference to a variant with the given index, if it exists

Source

pub fn enum_repr(&self) -> Option<EnumRepr>

Returns the enum representation, if this shape represents an enum

Trait Implementations§

Source§

impl Clone for Shape

Source§

fn clone(&self) -> Shape

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 Shape

Source§

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

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

impl Display for Shape

Source§

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

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

impl Hash for Shape

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 PartialEq for Shape

Source§

fn eq(&self, other: &Self) -> 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 Copy for Shape

Source§

impl Eq for Shape

Auto Trait Implementations§

§

impl Freeze for Shape

§

impl RefUnwindSafe for Shape

§

impl Send for Shape

§

impl Sync for Shape

§

impl Unpin for Shape

§

impl UnwindSafe for Shape

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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.