pub enum AlgebraicValue {
    Sum(SumValue),
    Product(ProductValue),
    Builtin(BuiltinValue),
}
Expand description

A value in SATS typed at some AlgebraicType.

Values are type erased, so they do not store their type. This is important mainly for space efficiency, including network latency and bandwidth.

These are only values and not expressions. That is, they are canonical and cannot be simplified further by some evaluation. So forms like 42 + 24 are not represented in an AlgebraicValue.

Variants§

§

Sum(SumValue)

A structural sum value.

Given a sum type { N_0(T_0), N_1(T_1), ..., N_n(T_n) } where N_i denotes a variant name and where T_i denotes the type the variant stores, a sum value makes a specific choice as to the variant. So for example, we might chose N_1(T_1) and represent this choice with (1, v) where v is a value of type T_1.

§

Product(ProductValue)

A structural product value.

Given a product type { N_0: T_0, N_1: T_1, ..., N_n: T_n } where N_i denotes a field / element name and where T_i denotes the type the field stores, a product value stores a value v_i of type T_i for each field N_i.

§

Builtin(BuiltinValue)

A builtin value that has a builtin type.

Implementations§

source§

impl AlgebraicValue

source

pub fn is_sum(&self) -> bool

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

source

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

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

source

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

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

source

pub fn into_sum(self) -> Result<SumValue, AlgebraicValue>

Returns the inner fields if this is a AlgebraicValue::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 AlgebraicValue::Product, otherwise false

source

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

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

source

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

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

source

pub fn into_product(self) -> Result<ProductValue, AlgebraicValue>

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

source

pub fn is_builtin(&self) -> bool

Returns true if this is a AlgebraicValue::Builtin, otherwise false

source

pub fn as_builtin_mut(&mut self) -> Option<&mut BuiltinValue>

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

source

pub fn as_builtin(&self) -> Option<&BuiltinValue>

Optionally returns references to the inner fields if this is a AlgebraicValue::Builtin, otherwise None

source

pub fn into_builtin(self) -> Result<BuiltinValue, AlgebraicValue>

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

source§

impl AlgebraicValue

source

pub const UNIT: AlgebraicValue = Self::product(Vec::new())

The canonical unit value defined as the nullary product value ().

The type of UNIT is ().

source

pub fn as_bool(&self) -> Option<&bool>

Interpret the value as a bool or None if it isn’t a bool value.

source

pub fn as_i8(&self) -> Option<&i8>

Interpret the value as an i8 or None if it isn’t a i8 value.

source

pub fn as_u8(&self) -> Option<&u8>

Interpret the value as a u8 or None if it isn’t a u8 value.

source

pub fn as_i16(&self) -> Option<&i16>

Interpret the value as an i16 or None if it isn’t an i16 value.

source

pub fn as_u16(&self) -> Option<&u16>

Interpret the value as a u16 or None if it isn’t a u16 value.

source

pub fn as_i32(&self) -> Option<&i32>

Interpret the value as an i32 or None if it isn’t an i32 value.

source

pub fn as_u32(&self) -> Option<&u32>

Interpret the value as a u32 or None if it isn’t a u32 value.

source

pub fn as_i64(&self) -> Option<&i64>

Interpret the value as an i64 or None if it isn’t an i64 value.

source

pub fn as_u64(&self) -> Option<&u64>

Interpret the value as a u64 or None if it isn’t a u64 value.

source

pub fn as_i128(&self) -> Option<&i128>

Interpret the value as an i128 or None if it isn’t an i128 value.

source

pub fn as_u128(&self) -> Option<&u128>

Interpret the value as a u128 or None if it isn’t a u128 value.

source

pub fn as_f32(&self) -> Option<&ConstrainedFloat<f32, UnitConstraint<f32>>>

Interpret the value as a f32 or None if it isn’t a f32 value.

source

pub fn as_f64(&self) -> Option<&ConstrainedFloat<f64, UnitConstraint<f64>>>

Interpret the value as a f64 or None if it isn’t a f64 value.

source

pub fn as_string(&self) -> Option<&String>

Interpret the value as a String or None if it isn’t a String value.

source

pub fn as_bytes(&self) -> Option<&Vec<u8, Global>>

Interpret the value as a Vec<u8> or None if it isn’t a Vec<u8> value.

source

pub fn as_array(&self) -> Option<&ArrayValue>

Interpret the value as an ArrayValue or None if it isn’t an ArrayValue value.

source

pub fn as_map( &self ) -> Option<&BTreeMap<AlgebraicValue, AlgebraicValue, Global>>

Interpret the value as a map or None if it isn’t a map value.

source

pub fn into_bool(self) -> Result<bool, AlgebraicValue>

Convert the value into a bool or Err(self) if it isn’t a bool value.

source

pub fn into_i8(self) -> Result<i8, AlgebraicValue>

Convert the value into an i8 or Err(self) if it isn’t an i8 value.

source

pub fn into_u8(self) -> Result<u8, AlgebraicValue>

Convert the value into a u8 or Err(self) if it isn’t a u8 value.

source

pub fn into_i16(self) -> Result<i16, AlgebraicValue>

Convert the value into an i16 or Err(self) if it isn’t an i16 value.

source

pub fn into_u16(self) -> Result<u16, AlgebraicValue>

Convert the value into a u16 or Err(self) if it isn’t a u16 value.

source

pub fn into_i32(self) -> Result<i32, AlgebraicValue>

Convert the value into an i32 or Err(self) if it isn’t an i32 value.

source

pub fn into_u32(self) -> Result<u32, AlgebraicValue>

Convert the value into a u32 or Err(self) if it isn’t a u32 value.

source

pub fn into_i64(self) -> Result<i64, AlgebraicValue>

Convert the value into an i64 or Err(self) if it isn’t an i64 value.

source

pub fn into_u64(self) -> Result<u64, AlgebraicValue>

Convert the value into a u64 or Err(self) if it isn’t a u64 value.

source

pub fn into_i128(self) -> Result<i128, AlgebraicValue>

Convert the value into an i128 or Err(self) if it isn’t an i128 value.

source

pub fn into_u128(self) -> Result<u128, AlgebraicValue>

Convert the value into a u128 or Err(self) if it isn’t a u128 value.

source

pub fn into_f32( self ) -> Result<ConstrainedFloat<f32, UnitConstraint<f32>>, AlgebraicValue>

Convert the value into a f32 or Err(self) if it isn’t a f32 value.

source

pub fn into_f64( self ) -> Result<ConstrainedFloat<f64, UnitConstraint<f64>>, AlgebraicValue>

Convert the value into a f64 or Err(self) if it isn’t a f64 value.

source

pub fn into_string(self) -> Result<String, AlgebraicValue>

Convert the value into a String or Err(self) if it isn’t a String value.

source

pub fn into_bytes(self) -> Result<Vec<u8, Global>, AlgebraicValue>

Convert the value into a Vec<u8> or Err(self) if it isn’t a Vec<u8> value.

source

pub fn into_array(self) -> Result<ArrayValue, AlgebraicValue>

Convert the value into an ArrayValue or Err(self) if it isn’t an ArrayValue value.

source

pub fn into_map( self ) -> Result<BTreeMap<AlgebraicValue, AlgebraicValue, Global>, AlgebraicValue>

Convert the value into a map or Err(self) if it isn’t a map value.

source

pub const fn Bool(v: bool) -> AlgebraicValue

Returns an AlgebraicValue representing v: bool.

source

pub const fn I8(v: i8) -> AlgebraicValue

Returns an AlgebraicValue representing v: i8.

source

pub const fn U8(v: u8) -> AlgebraicValue

Returns an AlgebraicValue representing v: u8.

source

pub const fn I16(v: i16) -> AlgebraicValue

Returns an AlgebraicValue representing v: i16.

source

pub const fn U16(v: u16) -> AlgebraicValue

Returns an AlgebraicValue representing v: u16.

source

pub const fn I32(v: i32) -> AlgebraicValue

Returns an AlgebraicValue representing v: i32.

source

pub const fn U32(v: u32) -> AlgebraicValue

Returns an AlgebraicValue representing v: u32.

source

pub const fn I64(v: i64) -> AlgebraicValue

Returns an AlgebraicValue representing v: i64.

source

pub const fn U64(v: u64) -> AlgebraicValue

Returns an AlgebraicValue representing v: u64.

source

pub const fn I128(v: i128) -> AlgebraicValue

Returns an AlgebraicValue representing v: i128.

source

pub const fn U128(v: u128) -> AlgebraicValue

Returns an AlgebraicValue representing v: u128.

source

pub const fn F32( v: ConstrainedFloat<f32, UnitConstraint<f32>> ) -> AlgebraicValue

Returns an AlgebraicValue representing v: f32.

source

pub const fn F64( v: ConstrainedFloat<f64, UnitConstraint<f64>> ) -> AlgebraicValue

Returns an AlgebraicValue representing v: f64.

source

pub const fn String(v: String) -> AlgebraicValue

Returns an AlgebraicValue representing v: String.

source

pub const fn Bytes(v: Vec<u8, Global>) -> AlgebraicValue

Returns an AlgebraicValue representing v: Vec<u8>.

source

pub fn ArrayOf(val: impl Into<ArrayValue>) -> AlgebraicValue

Returns an AlgebraicValue for a val which can be converted into an ArrayValue.

source

pub fn OptionSome(v: AlgebraicValue) -> AlgebraicValue

Returns an AlgebraicValue for some: v.

The some variant is assigned the tag 0.

source

pub fn OptionNone() -> AlgebraicValue

Returns an AlgebraicValue for none.

The none variant is assigned the tag 1.

source

pub fn sum(tag: u8, value: AlgebraicValue) -> AlgebraicValue

Returns an AlgebraicValue representing a sum value with tag and value.

source

pub const fn product(elements: Vec<AlgebraicValue, Global>) -> AlgebraicValue

Returns an AlgebraicValue representing a product value with the given elements.

source

pub const fn map( map: BTreeMap<AlgebraicValue, AlgebraicValue, Global> ) -> AlgebraicValue

Returns an AlgebraicValue representing a map value defined by the given map.

source

pub fn type_of(&self) -> AlgebraicType

Infer the AlgebraicType of an AlgebraicValue.

source§

impl AlgebraicValue

source

pub fn decode<'a>( algebraic_type: &<AlgebraicValue as Value>::Type, bytes: &mut impl BufReader<'a> ) -> Result<AlgebraicValue, DecodeError>

source

pub fn encode(&self, bytes: &mut impl BufWriter)

Trait Implementations§

source§

impl Clone for AlgebraicValue

source§

fn clone(&self) -> AlgebraicValue

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 AlgebraicValue

source§

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

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

impl From<&[u8]> for AlgebraicValue

source§

fn from(x: &[u8]) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<&AlgebraicValue> for ProductValue

source§

fn from(x: &AlgebraicValue) -> ProductValue

Converts to this type from the input type.
source§

impl From<&str> for AlgebraicValue

source§

fn from(x: &str) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<AlgebraicValue> for FieldExpr

source§

fn from(x: AlgebraicValue) -> Self

Converts to this type from the input type.
source§

impl From<AlgebraicValue> for ProductValue

source§

fn from(x: AlgebraicValue) -> ProductValue

Converts to this type from the input type.
source§

impl From<BuiltinValue> for AlgebraicValue

source§

fn from(value: BuiltinValue) -> AlgebraicValue

Converts to this type from the input type.
source§

impl<T> From<Option<T>> for AlgebraicValuewhere T: Into<AlgebraicValue>,

source§

fn from(value: Option<T>) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<ProductValue> for AlgebraicValue

source§

fn from(x: ProductValue) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<String> for AlgebraicValue

source§

fn from(x: String) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<bool> for AlgebraicValue

source§

fn from(x: bool) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<f32> for AlgebraicValue

source§

fn from(x: f32) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<f64> for AlgebraicValue

source§

fn from(x: f64) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<i128> for AlgebraicValue

source§

fn from(x: i128) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<i16> for AlgebraicValue

source§

fn from(x: i16) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<i32> for AlgebraicValue

source§

fn from(x: i32) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<i64> for AlgebraicValue

source§

fn from(x: i64) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<i8> for AlgebraicValue

source§

fn from(x: i8) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<u128> for AlgebraicValue

source§

fn from(x: u128) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<u16> for AlgebraicValue

source§

fn from(x: u16) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<u32> for AlgebraicValue

source§

fn from(x: u32) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<u64> for AlgebraicValue

source§

fn from(x: u64) -> AlgebraicValue

Converts to this type from the input type.
source§

impl From<u8> for AlgebraicValue

source§

fn from(x: u8) -> AlgebraicValue

Converts to this type from the input type.
source§

impl FromIterator<AlgebraicValue> for ProductValue

source§

fn from_iter<T>(iter: T) -> ProductValuewhere T: IntoIterator<Item = AlgebraicValue>,

Creates a value from an iterator. Read more
source§

impl Hash for AlgebraicValue

source§

fn hash<__H>(&self, state: &mut __H)where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for AlgebraicValue

source§

fn cmp(&self, other: &AlgebraicValue) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<AlgebraicValue> for AlgebraicValue

source§

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

source§

fn partial_cmp(&self, other: &AlgebraicValue) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for AlgebraicValue

source§

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

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

impl Serialize for AlgebraicValue

source§

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

Serialize this value into the given Serde serializer. Read more
source§

impl ToDataKey for AlgebraicValue

source§

impl Value for AlgebraicValue

§

type Type = AlgebraicType

The type of this value.
source§

impl Eq for AlgebraicValue

source§

impl StructuralEq for AlgebraicValue

source§

impl StructuralPartialEq for AlgebraicValue

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

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

source§

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

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

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

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 Twhere 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 Twhere 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 Twhere 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.