Enum AlgebraicTypeLayout

Source
pub enum AlgebraicTypeLayout {
    Sum(SumTypeLayout),
    Product(ProductTypeLayout),
    Primitive(PrimitiveType),
    VarLen(VarLenType),
}
Expand description

Mostly a mirror of AlgebraicType annotated with a Layout.

Notable differences from AlgebraicType:

  • Refs are not supported. Supporting recursive types remains a TODO(future-work). Note that the previous Spacetime datastore did not support recursive types in tables.

  • Scalar types (ty.is_scalar()) are separated into PrimitiveType (atomically-sized types like integers).

  • Variable length types are separated into VarLenType (strings, arrays, and maps). This separation allows cleaner pattern-matching, e.g. in HasLayout::layout, where VarLenType returns a static ref to [VAR_LEN_REF_LAYOUT], and PrimitiveType dispatches on its variant to return a static ref to a type-specific Layout.

Variants§

§

Sum(SumTypeLayout)

A sum type, annotated with its layout.

§

Product(ProductTypeLayout)

A product type, annotated with its layout.

§

Primitive(PrimitiveType)

A primitive type, annotated with its layout.

§

VarLen(VarLenType)

A variable length type, annotated with its layout.

Implementations§

Source§

impl AlgebraicTypeLayout

Source

pub fn is_sum(&self) -> bool

Returns true if this is a AlgebraicTypeLayout::Sum, otherwise false

Source

pub fn as_sum_mut(&mut self) -> Option<&mut SumTypeLayout>

Optionally returns mutable references to the inner fields if this is a AlgebraicTypeLayout::Sum, otherwise None

Source

pub fn as_sum(&self) -> Option<&SumTypeLayout>

Optionally returns references to the inner fields if this is a AlgebraicTypeLayout::Sum, otherwise None

Source

pub fn into_sum(self) -> Result<SumTypeLayout, Self>

Returns the inner fields if this is a AlgebraicTypeLayout::Sum, otherwise returns back the enum in the Err case of the result

Source

pub fn is_product(&self) -> bool

Returns true if this is a AlgebraicTypeLayout::Product, otherwise false

Source

pub fn as_product_mut(&mut self) -> Option<&mut ProductTypeLayout>

Optionally returns mutable references to the inner fields if this is a AlgebraicTypeLayout::Product, otherwise None

Source

pub fn as_product(&self) -> Option<&ProductTypeLayout>

Optionally returns references to the inner fields if this is a AlgebraicTypeLayout::Product, otherwise None

Source

pub fn into_product(self) -> Result<ProductTypeLayout, Self>

Returns the inner fields if this is a AlgebraicTypeLayout::Product, otherwise returns back the enum in the Err case of the result

Source

pub fn is_primitive(&self) -> bool

Returns true if this is a AlgebraicTypeLayout::Primitive, otherwise false

Source

pub fn as_primitive_mut(&mut self) -> Option<&mut PrimitiveType>

Optionally returns mutable references to the inner fields if this is a AlgebraicTypeLayout::Primitive, otherwise None

Source

pub fn as_primitive(&self) -> Option<&PrimitiveType>

Optionally returns references to the inner fields if this is a AlgebraicTypeLayout::Primitive, otherwise None

Source

pub fn into_primitive(self) -> Result<PrimitiveType, Self>

Returns the inner fields if this is a AlgebraicTypeLayout::Primitive, otherwise returns back the enum in the Err case of the result

Source

pub fn is_var_len(&self) -> bool

Returns true if this is a AlgebraicTypeLayout::VarLen, otherwise false

Source

pub fn as_var_len_mut(&mut self) -> Option<&mut VarLenType>

Optionally returns mutable references to the inner fields if this is a AlgebraicTypeLayout::VarLen, otherwise None

Source

pub fn as_var_len(&self) -> Option<&VarLenType>

Optionally returns references to the inner fields if this is a AlgebraicTypeLayout::VarLen, otherwise None

Source

pub fn into_var_len(self) -> Result<VarLenType, Self>

Returns the inner fields if this is a AlgebraicTypeLayout::VarLen, otherwise returns back the enum in the Err case of the result

Source§

impl AlgebraicTypeLayout

Source

pub const Bool: Self

Source

pub const I8: Self

Source

pub const U8: Self

Source

pub const I16: Self

Source

pub const U16: Self

Source

pub const I32: Self

Source

pub const U32: Self

Source

pub const I64: Self

Source

pub const U64: Self

Source

pub const I128: Self

Source

pub const U128: Self

Source

pub const I256: Self

Source

pub const U256: Self

Source

pub const F32: Self

Source

pub const F64: Self

Source

pub const String: Self

Source§

impl AlgebraicTypeLayout

Source

pub fn algebraic_type(&self) -> AlgebraicType

Convert an AlgebraicTypeLayout back into an AlgebraicType, removing layout information.

This operation is O(n) in the number of nodes in the argument, and may heap-allocate. It is intended for use in error paths, where performance is a secondary concern.

Trait Implementations§

Source§

impl Clone for AlgebraicTypeLayout

Source§

fn clone(&self) -> AlgebraicTypeLayout

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 AlgebraicTypeLayout

Source§

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

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

impl<'de> DeserializeSeed<'de> for &AlgebraicTypeLayout

Source§

type Output = AlgebraicValue

The type produced by using this seed.
Source§

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

Equivalent to the more common Deserialize::deserialize associated function, except with some initial piece of data (the seed self) passed in.
Source§

impl From<AlgebraicType> for AlgebraicTypeLayout

Source§

fn from(ty: AlgebraicType) -> Self

Converts to this type from the input type.
Source§

impl HasLayout for AlgebraicTypeLayout

Source§

fn layout(&self) -> &Layout

Returns the layout for objects of this type.
Source§

fn size(&self) -> usize

Returns the size, in bytes, for objects of this type. Read more
Source§

fn align(&self) -> usize

Returns the alignment, in bytes, for objects of this type. Read more
Source§

impl MemoryUsage for AlgebraicTypeLayout

Source§

fn heap_usage(&self) -> usize

The heap memory usage of this type. The default implementation returns 0.
Source§

impl PartialEq for AlgebraicTypeLayout

Source§

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

Source§

impl StructuralPartialEq for AlgebraicTypeLayout

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

Source§

type Output = T

Should always be Self
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.