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.

  • BuiltinType is separated into [PrimitveType] (atomically-sized types like integers) and 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 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 Debug for AlgebraicTypeLayout

source§

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

Formats the value using the given formatter. Read more
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 PartialEq for AlgebraicTypeLayout

source§

fn eq(&self, other: &AlgebraicTypeLayout) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more