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
impl TypeDescriptor
Sourcepub 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
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.
Sourcepub const fn with_owned_bytes(self, owned_bytes: OwnedBytesFn) -> TypeDescriptor
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.
Sourcepub unsafe fn owned_bytes_of(&self, payload: *const u8) -> usize
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.
Sourcepub const fn as_builtin(&self) -> Option<BuiltinTypeId>
pub const fn as_builtin(&self) -> Option<BuiltinTypeId>
Which built-in this descriptor is, if any.
Sourcepub fn is_equatable(&self) -> bool
pub fn is_equatable(&self) -> bool
True iff values of this type participate in structural equality (§5.5).
Sourcepub fn is_hashable(&self) -> bool
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.
Sourcepub fn is_orderable(&self) -> bool
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
impl Clone for TypeDescriptor
Source§fn clone(&self) -> TypeDescriptor
fn clone(&self) -> TypeDescriptor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more