Skip to main content

TypeDescriptor

Struct TypeDescriptor 

Source
pub struct TypeDescriptor {
    pub name: &'static str,
    pub trace: TraceFn,
    pub drop_value: DropFn,
    pub format: FormatFn,
    pub equals: Option<EqualsFn>,
    pub hash: Option<HashFn>,
    pub compare: Option<CompareFn>,
    pub owned_bytes: Option<OwnedBytesFn>,
    /* private fields */
}
Expand description

Centralized table of operations on a value’s payload (§11.4).

Exact Rust types may evolve, but all payload-aware operations must live here rather than in scattered type switches.

id, size and align are private and derived: a built-in descriptor is constructible only through TypeDescriptor::builtin, which takes the BuiltinTypeId the id comes from and the payload type the layout comes from. “A descriptor whose id names a different type” and “a descriptor whose size disagrees with its payload” are therefore unrepresentable.

Fields§

§name: &'static str§trace: TraceFn§drop_value: DropFn§format: FormatFn§equals: Option<EqualsFn>§hash: Option<HashFn>§compare: Option<CompareFn>§owned_bytes: Option<OwnedBytesFn>

Bytes this value owns outside its allocation block, for GC pacing. None means none — the scalar case, and the default. Set with TypeDescriptor::with_owned_bytes.

Implementations§

Source§

impl TypeDescriptor

Source

pub const fn builtin<P>( builtin: BuiltinTypeId, name: &'static str, trace: TraceFn, drop_value: DropFn, format: FormatFn, equals: Option<EqualsFn>, hash: Option<HashFn>, compare: Option<CompareFn>, ) -> TypeDescriptor

The only constructor for a built-in descriptor. id is derived from builtin; size/align are derived from the payload type P.

Built-in descriptors must be declared as static, never const: a const reference is a promoted rvalue with no guaranteed unique address, and descriptor pointer identity is what the runtime compares.

Source

pub const fn with_owned_bytes(self, owned_bytes: OwnedBytesFn) -> TypeDescriptor

Declare that this type owns memory outside its allocation block, and how to measure it.

A builder rather than a constructor argument because the default — “nothing beyond the payload” — is right for every scalar and for VarCell and Range, and a required argument would make each of those declarations spell out the same None.

Source

pub unsafe fn owned_bytes_of(&self, payload: *const u8) -> usize

Bytes payload owns outside its allocation block, or 0 if this type owns nothing beyond its payload.

§Safety

payload must point at a value of this descriptor’s type.

Source

pub const fn id(&self) -> TypeId

This descriptor’s type identity.

Source

pub const fn as_builtin(&self) -> Option<BuiltinTypeId>

Which built-in this descriptor is, if any.

Source

pub const fn size(&self) -> usize

Size in bytes of this type’s payload.

Source

pub const fn align(&self) -> usize

Alignment in bytes of this type’s payload.

Source

pub fn is_equatable(&self) -> bool

True iff values of this type participate in structural equality (§5.5).

Source

pub fn is_hashable(&self) -> bool

True iff values of this type have a structural hash (§5.5).

Not the same as “may be a Map key”: a Vec hashes and can never be a key (ADR-057 D4). That question is praxis_hir::capability::supports_hash_stable.

Source

pub fn is_orderable(&self) -> bool

True iff values of this type have a container order — the sequence a Map, Set, Counter or heap puts them in (ADR-138).

Not the source language’s <: that is praxis_hir::capability::supports_ord, and it is a strictly smaller set on purpose. A tuple answers true here and is still refused by <.

Trait Implementations§

Source§

impl Clone for TypeDescriptor

Source§

fn clone(&self) -> TypeDescriptor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for TypeDescriptor

Source§

impl Debug for TypeDescriptor

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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.