Struct spacetimedb_sats::typespace::Typespace

source ·
pub struct Typespace {
    pub types: Vec<AlgebraicType>,
}
Expand description

A Typespace represents the typing context in SATS.

That is, this is the Δ or Γ you’ll see in type theory litterature.

We use (sort of) deBrujin indices to represent our type variables. Notably however, these are given for the entire module and there are no universal quantifiers (i.e., Δ, α ⊢ τ | Δ ⊢ ∀ α. τ) nor are there type lambdas (i.e., Λτ. v). See System F, the second-order lambda calculus, for more on and Λ.

There are however recursive types in SATs, e.g., &0 = { Cons({ v: U8, t: &0 }), Nil } represents a basic cons list where &0 is the type reference at index 0.

Fields§

§types: Vec<AlgebraicType>

The types in our typing context that can be referred to with AlgebraicTypeRefs.

Implementations§

source§

impl Typespace

source

pub const EMPTY: &'static Typespace = _

source

pub const fn new(types: Vec<AlgebraicType>) -> Self

Returns a context (Typespace) with the given types.

source

pub fn get(&self, r: AlgebraicTypeRef) -> Option<&AlgebraicType>

Returns the AlgebraicType referred to by r within this context.

source

pub fn get_mut(&mut self, r: AlgebraicTypeRef) -> Option<&mut AlgebraicType>

Returns a mutable reference to the AlgebraicType referred to by r within this context.

source

pub fn add(&mut self, ty: AlgebraicType) -> AlgebraicTypeRef

Inserts an AlgebraicType into the typespace and returns an AlgebraicTypeRef that refers to the inserted AlgebraicType.

This allows for self referential, recursive or other complex types to be declared in the typespace.

You can also use this to later change the meaning of the returned AlgebraicTypeRef when you cannot provide the full definition of the type yet.

Panics if the number of type references exceeds an u32.

source

pub const fn with_type<'a, T: ?Sized>( &'a self, ty: &'a T ) -> WithTypespace<'a, T>

Returns ty combined with the context self.

source

pub fn inline_typerefs_in_type( &mut self, ty: &mut AlgebraicType ) -> Result<(), TypeRefError>

Inlines all type references in ty recursively using the current typeset.

source

pub fn inline_all_typerefs(&mut self) -> Result<(), TypeRefError>

Inlines all type references in the typespace recursively.

Errors out if any type reference is invalid or self-referential.

Trait Implementations§

source§

impl Clone for Typespace

source§

fn clone(&self) -> Typespace

Returns a copy 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 Typespace

source§

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

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

impl Default for Typespace

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Typespace

source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given deserializer.
source§

impl Index<AlgebraicTypeRef> for Typespace

§

type Output = AlgebraicType

The returned type after indexing.
source§

fn index(&self, index: AlgebraicTypeRef) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<AlgebraicTypeRef> for Typespace

source§

fn index_mut(&mut self, index: AlgebraicTypeRef) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl Serialize for Typespace

source§

fn serialize<S: Serializer>(&self, __serializer: S) -> Result<S::Ok, S::Error>

Serialize self in the data format of S using the provided serializer.

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> Satn for T
where T: Serialize + ?Sized,

source§

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

Formats the value using the SATN data format into the formatter f.
source§

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

Formats the value using the postgres SATN data format into the formatter f.
source§

fn to_satn(&self) -> String

Formats the value using the SATN data format into the returned String.
source§

fn to_satn_pretty(&self) -> String

Pretty prints the value using the SATN data format into the returned String.
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,