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:
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
pub fn decode<'a>( bytes: &mut impl BufReader<'a>, ) -> Result<ProductType, DecodeError>
pub fn encode(&self, bytes: &mut impl BufWriter)
Source§impl ProductType
impl ProductType
Sourcepub const fn new(elements: Box<[ProductTypeElement]>) -> ProductType
pub const fn new(elements: Box<[ProductTypeElement]>) -> ProductType
Returns a product type with the given elements as its factors.
Sourcepub fn unit() -> ProductType
pub fn unit() -> ProductType
Returns the unit product type.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Returns whether this is the special case of spacetimedb_lib::Identity.
Does not follow Refs.
Sourcepub fn is_connection_id(&self) -> bool
pub fn is_connection_id(&self) -> bool
Returns whether this is the special case of spacetimedb_lib::ConnectionId.
Does not follow Refs.
Sourcepub fn is_timestamp(&self) -> bool
pub fn is_timestamp(&self) -> bool
Returns whether this is the special case of spacetimedb_lib::Timestamp.
Does not follow Refs.
Sourcepub fn is_time_duration(&self) -> bool
pub fn is_time_duration(&self) -> bool
Returns whether this is the special case of spacetimedb_lib::TimeDuration.
Does not follow Refs.
Sourcepub fn is_identity_tag(tag_name: &str) -> bool
pub fn is_identity_tag(tag_name: &str) -> bool
Returns whether this is the special tag of Identity.
Sourcepub fn is_connection_id_tag(tag_name: &str) -> bool
pub fn is_connection_id_tag(tag_name: &str) -> bool
Returns whether this is the special tag of ConnectionId.
Sourcepub fn is_timestamp_tag(tag_name: &str) -> bool
pub fn is_timestamp_tag(tag_name: &str) -> bool
Returns whether this is the special tag of crate::timestamp::Timestamp.
Sourcepub fn is_time_duration_tag(tag_name: &str) -> bool
pub fn is_time_duration_tag(tag_name: &str) -> bool
Returns whether this is the special tag of crate::time_duration::TimeDuration.
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, Identity, Timestamp or TimeDuration.
Sourcepub fn is_special(&self) -> bool
pub fn is_special(&self) -> bool
Returns whether this is a special known type, currently ConnectionId or Identity.
Does not follow Refs.
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.
Sourcepub fn project(
&self,
cols: &ColList,
) -> Result<AlgebraicType, InvalidFieldError>
pub fn project( &self, cols: &ColList, ) -> Result<AlgebraicType, InvalidFieldError>
This utility function is designed to project fields based on the supplied indexes.
Important:
The resulting AlgebraicType will wrap into a ProductType when projecting multiple (including zero) fields, otherwise it will consist of a single AlgebraicType.
Parameters:
cols: A ColList containing the indexes of fields to be projected.
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: D,
) -> Result<ProductType, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<ProductType, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
deserializer.Source§impl<'de> Deserialize<'de> for ProductType
impl<'de> Deserialize<'de> for ProductType
Source§fn deserialize<D>(
deserializer: D,
) -> Result<ProductType, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<ProductType, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<const N: usize> From<[(&str, AlgebraicType); N]> for ProductType
impl<const N: usize> From<[(&str, AlgebraicType); N]> for ProductType
Source§fn from(fields: [(&str, AlgebraicType); N]) -> ProductType
fn from(fields: [(&str, AlgebraicType); N]) -> 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§fn from(fields: [(Option<&str>, AlgebraicType); N]) -> ProductType
fn from(fields: [(Option<&str>, AlgebraicType); N]) -> 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]) -> ProductType
fn from(fields: [AlgebraicType; N]) -> ProductType
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]) -> ProductType
fn from(fields: [ProductTypeElement; N]) -> ProductType
Source§impl From<AlgebraicType> for ProductType
impl From<AlgebraicType> for ProductType
Source§fn from(x: AlgebraicType) -> ProductType
fn from(x: AlgebraicType) -> ProductType
Source§impl From<Box<[ProductTypeElement]>> for ProductType
impl From<Box<[ProductTypeElement]>> for ProductType
Source§fn from(fields: Box<[ProductTypeElement]>) -> ProductType
fn from(fields: Box<[ProductTypeElement]>) -> ProductType
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> FromIterator<(&'a str, I)> for ProductTypewhere
I: Into<AlgebraicType>,
impl<'a, I> FromIterator<(&'a str, I)> for ProductTypewhere
I: Into<AlgebraicType>,
Source§fn from_iter<T>(iter: T) -> ProductTypewhere
T: IntoIterator<Item = (&'a str, I)>,
fn from_iter<T>(iter: T) -> ProductTypewhere
T: IntoIterator<Item = (&'a str, I)>,
Source§impl<'a, I> FromIterator<(Option<&'a str>, I)> for ProductTypewhere
I: Into<AlgebraicType>,
impl<'a, I> FromIterator<(Option<&'a str>, I)> for ProductTypewhere
I: Into<AlgebraicType>,
Source§fn from_iter<T>(iter: T) -> ProductType
fn from_iter<T>(iter: T) -> ProductType
Source§impl<I> FromIterator<I> for ProductTypewhere
I: Into<ProductTypeElement>,
impl<I> FromIterator<I> for ProductTypewhere
I: Into<ProductTypeElement>,
Source§fn from_iter<T>(iter: T) -> ProductTypewhere
T: IntoIterator<Item = I>,
fn from_iter<T>(iter: T) -> ProductTypewhere
T: IntoIterator<Item = I>,
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
Source§fn serialize<S>(
&self,
__serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
__serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
self in the data format of S using the provided serializer.Source§impl Serialize for ProductType
impl Serialize for ProductType
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl SpacetimeType for ProductType
impl SpacetimeType for ProductType
Source§fn make_type<S>(__typespace: &mut S) -> AlgebraicTypewhere
S: TypespaceBuilder,
fn make_type<S>(__typespace: &mut S) -> AlgebraicTypewhere
S: TypespaceBuilder,
AlgebraicType representing the type for Self in SATS
and in the typing context in typespace. This is used by the
automatic type registration system in Rust modules. Read moreimpl 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§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
f.Source§fn fmt_psql(
&self,
f: &mut Formatter<'_>,
ty: &PsqlType<'_>,
) -> Result<(), Error>
fn fmt_psql( &self, f: &mut Formatter<'_>, ty: &PsqlType<'_>, ) -> Result<(), Error>
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.