Struct spacetimedb_sats::product_type::ProductType
source · pub struct ProductType {
pub elements: Box<[ProductTypeElement]>,
}
Expand description
A structural product type of the factors given by elements
.
This is also known as struct
and tuple
in many languages,
but note that unlike most languages, products in SATs are structural and not nominal.
When checking whether two nominal types are the same,
their names and/or declaration sites (e.g., module / namespace) are considered.
Meanwhile, a structural type system would only check the structure of the type itself,
e.g., the names of its fields and their types in the case of a record.
The name “product” comes from category theory.
See also: https://ncatlab.org/nlab/show/product+type.
These structures are known as product types because the number of possible values in product
{ N_0: T_0, N_1: T_1, ..., N_n: T_n }
is:
Π (i ∈ 0..n). values(T_i)
so for example, values({ A: U64, B: Bool }) = values(U64) * values(Bool)
.
Fields§
§elements: Box<[ProductTypeElement]>
The factors of the product type.
These factors can either be named or unnamed. When all the factors are unnamed, we can regard this as a plain tuple type.
Implementations§
source§impl ProductType
impl ProductType
source§impl ProductType
impl ProductType
sourcepub const fn new(elements: Box<[ProductTypeElement]>) -> Self
pub const fn new(elements: Box<[ProductTypeElement]>) -> Self
Returns a product type with the given elements
as its factors.
sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Returns whether this is the special case of spacetimedb_lib::Identity
.
sourcepub fn is_address(&self) -> bool
pub fn is_address(&self) -> bool
Returns whether this is the special case of spacetimedb_lib::Address
.
sourcepub fn is_special_tag(tag_name: &str) -> bool
pub fn is_special_tag(tag_name: &str) -> bool
Returns whether this is a special known tag
, currently Address
or Identity
.
sourcepub fn is_special(&self) -> bool
pub fn is_special(&self) -> bool
Returns whether this is a special known type, currently Address
or Identity
.
sourcepub fn index_of_field_name(&self, name: &str) -> Option<usize>
pub fn index_of_field_name(&self, name: &str) -> Option<usize>
Returns index of the field with the given name
.
source§impl ProductType
impl ProductType
pub fn as_value(&self) -> AlgebraicValue
pub fn from_value( value: &AlgebraicValue, ) -> Result<ProductType, ValueDeserializeError>
Trait Implementations§
source§impl Clone for ProductType
impl Clone for ProductType
source§fn clone(&self) -> ProductType
fn clone(&self) -> ProductType
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ProductType
impl Debug for ProductType
source§impl<'de> Deserialize<'de> for ProductType
impl<'de> Deserialize<'de> for ProductType
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
deserializer
.source§impl<const N: usize> From<[(&str, AlgebraicType); N]> for ProductType
impl<const N: usize> From<[(&str, AlgebraicType); N]> for ProductType
source§impl<const N: usize> From<[(Option<&str>, AlgebraicType); N]> for ProductType
impl<const N: usize> From<[(Option<&str>, AlgebraicType); N]> for ProductType
source§impl<const N: usize> From<[AlgebraicType; N]> for ProductType
impl<const N: usize> From<[AlgebraicType; N]> for ProductType
source§fn from(fields: [AlgebraicType; N]) -> Self
fn from(fields: [AlgebraicType; N]) -> Self
source§impl<const N: usize> From<[ProductTypeElement; N]> for ProductType
impl<const N: usize> From<[ProductTypeElement; N]> for ProductType
source§fn from(fields: [ProductTypeElement; N]) -> Self
fn from(fields: [ProductTypeElement; N]) -> Self
source§impl From<AlgebraicType> for ProductType
impl From<AlgebraicType> for ProductType
source§fn from(x: AlgebraicType) -> Self
fn from(x: AlgebraicType) -> Self
source§impl From<Box<[ProductTypeElement]>> for ProductType
impl From<Box<[ProductTypeElement]>> for ProductType
source§fn from(fields: Box<[ProductTypeElement]>) -> Self
fn from(fields: Box<[ProductTypeElement]>) -> Self
source§impl From<ProductType> for AlgebraicType
impl From<ProductType> for AlgebraicType
source§fn from(original: ProductType) -> AlgebraicType
fn from(original: ProductType) -> AlgebraicType
source§impl<'a, I: Into<AlgebraicType>> FromIterator<(&'a str, I)> for ProductType
impl<'a, I: Into<AlgebraicType>> FromIterator<(&'a str, I)> for ProductType
source§impl<'a, I: Into<AlgebraicType>> FromIterator<(Option<&'a str>, I)> for ProductType
impl<'a, I: Into<AlgebraicType>> FromIterator<(Option<&'a str>, I)> for ProductType
source§impl<I: Into<ProductTypeElement>> FromIterator<I> for ProductType
impl<I: Into<ProductTypeElement>> FromIterator<I> for ProductType
source§fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = I>>(iter: T) -> Self
source§impl Hash for ProductType
impl Hash for ProductType
source§impl MetaType for ProductType
impl MetaType for ProductType
source§fn meta_type() -> AlgebraicType
fn meta_type() -> AlgebraicType
AlgebraicType
.source§impl Ord for ProductType
impl Ord for ProductType
source§fn cmp(&self, other: &ProductType) -> Ordering
fn cmp(&self, other: &ProductType) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for ProductType
impl PartialEq for ProductType
source§impl PartialOrd for ProductType
impl PartialOrd for ProductType
source§impl Serialize for ProductType
impl Serialize for ProductType
impl Eq for ProductType
impl StructuralPartialEq for ProductType
Auto Trait Implementations§
impl Freeze for ProductType
impl RefUnwindSafe for ProductType
impl Send for ProductType
impl Sync for ProductType
impl Unpin for ProductType
impl UnwindSafe for ProductType
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<T> Satn for T
impl<T> Satn for T
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
f
.source§fn fmt_psql(&self, f: &mut Formatter<'_>, ty: &ProductType) -> Result
fn fmt_psql(&self, f: &mut Formatter<'_>, ty: &ProductType) -> Result
f
.source§fn to_satn(&self) -> String
fn to_satn(&self) -> String
String
.source§fn to_satn_pretty(&self) -> String
fn to_satn_pretty(&self) -> String
String
.