Skip to main content

TypeRef

Enum TypeRef 

Source
#[repr(u8)]
pub enum TypeRef<Id = SchemaHash> { Concrete { type_id: Id, args: Vec<TypeRef<Id>>, }, Var { name: TypeParamName, }, }
Expand description

A reference to a type in a schema. Either a concrete type (with optional type arguments for generics) or a type variable bound by the enclosing generic’s type_params.

Generic over the ID type: TypeSchemaId for final schemas, MixedId during extraction.

Variants§

§

Concrete

A concrete type, possibly generic.

Fields

§type_id: Id
§args: Vec<TypeRef<Id>>

Type arguments for generic types. Empty for non-generic types.

§

Var

A reference to a type parameter of the enclosing generic type, by name (e.g. TypeParamName("T")).

Fields

Implementations§

Source§

impl<Id> TypeRef<Id>

Source

pub fn concrete(type_id: Id) -> TypeRef<Id>

Shorthand for a non-generic concrete type reference.

Source

pub fn generic(type_id: Id, args: Vec<TypeRef<Id>>) -> TypeRef<Id>

Shorthand for a generic concrete type reference with type arguments.

Source

pub fn collect_ids(&self, out: &mut Vec<Id>)
where Id: Copy,

Collect all concrete IDs reachable from this TypeRef (depth-first).

Source

pub fn expect_concrete_id(&self) -> &Id

Return the concrete type ID if this is a non-generic Concrete variant, panicking otherwise.

Source

pub fn map<OtherId, F>(self, f: F) -> TypeRef<OtherId>
where F: Fn(Id) -> OtherId + Copy,

Map a TypeRef<Id> to TypeRef<OtherId> by applying f to every concrete ID.

Source

pub fn try_map<OtherId, E, F>(self, f: &F) -> Result<TypeRef<OtherId>, E>
where F: Fn(Id) -> Result<OtherId, E> + Copy,

Fallible version of map — applies f to every concrete ID, propagating errors.

Source§

impl TypeRef

Source

pub fn resolve_kind( &self, registry: &HashMap<SchemaHash, Schema>, ) -> Option<SchemaKind>

Look up the schema for this TypeRef in the registry and return the schema’s kind with all type variables substituted.

For non-generic types (Concrete { args: [] }), returns the kind as-is. For generic types, substitutes Var references with the concrete type arguments from this TypeRef.

Returns None if the schema is not in the registry or this is a Var.

Trait Implementations§

Source§

impl<Id> Clone for TypeRef<Id>
where Id: Clone,

Source§

fn clone(&self) -> TypeRef<Id>

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<Id> Debug for TypeRef<Id>
where Id: Debug,

Source§

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

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

impl<'ʄ, Id> Facet<'ʄ> for TypeRef<Id>
where Id: Facet<'ʄ>,

Source§

const SHAPE: &'static Shape

The shape of this type, including: whether it’s a Struct, an Enum, something else? Read more
Source§

impl<Id> Hash for TypeRef<Id>
where Id: Hash,

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

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<Id> PartialEq for TypeRef<Id>
where Id: PartialEq,

Source§

fn eq(&self, other: &TypeRef<Id>) -> 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<Id> Eq for TypeRef<Id>
where Id: Eq,

Source§

impl<Id> StructuralPartialEq for TypeRef<Id>

Auto Trait Implementations§

§

impl<Id> Freeze for TypeRef<Id>
where Id: Freeze,

§

impl<Id> RefUnwindSafe for TypeRef<Id>
where Id: RefUnwindSafe,

§

impl<Id> Send for TypeRef<Id>
where Id: Send,

§

impl<Id> Sync for TypeRef<Id>
where Id: Sync,

§

impl<Id> Unpin for TypeRef<Id>
where Id: Unpin,

§

impl<Id> UnsafeUnpin for TypeRef<Id>
where Id: UnsafeUnpin,

§

impl<Id> UnwindSafe for TypeRef<Id>
where Id: UnwindSafe,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.
Source§

impl<T> ChannelLiveness for T
where T: MaybeSend + MaybeSync + 'static,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,