Enum SubAggregator

Source
pub enum SubAggregator {
Show 25 variants Const(SemId, TinyBlob), TheOnly(StateName), Copy(StateName), Unwrap(StateName), First(StateName), Nth(StateName, u16), Last(StateName), NthBack(StateName, u16), Neg(StateSelector), Add(StateSelector, StateSelector), Sub(StateSelector, StateSelector), Mul(StateSelector, StateSelector), Div(StateSelector, StateSelector), Rem(StateSelector, StateSelector), Exp(StateSelector, StateSelector), Count(StateName), CountUnique(StateName), SetV(StateName), MapV2U(StateName), MapV2ListU(StateName), MapV2SetU(StateName), SumUnwrap(StateName), SumOrDefault(StateName), ProdUnwrap(StateName), ProdOrDefault(StateName),
}
Expand description

A set of pre-defined state sub-aggregators (see crate::Api::aggregators.

Variants§

§

Const(SemId, TinyBlob)

The aggregated state is generated with a predefined constant strict-encoded value.

To produce a state with a unit value, use Self::Const(SemId::unit(), none!()).

§

TheOnly(StateName)

Takes the only element of the global state.

Fails if the state is not defined or has more than one defined element.

§

Copy(StateName)

Takes some other aggregated and copies it.

Fails if the other aggregated state is not defined.

§

Unwrap(StateName)

Unwraps an optional value.

Fails if the value is None, is not defined, multiple, or not an optional.

§

First(StateName)

Takes the first element of the global state.

Fails if the global state is not defined, i.e., has zero elements.

§Nota bene

The global state does not have only a partial ordering (it is a lattice).

It is only in the case when one operation depends on outputs of another (via global or owned state) there is a guarantee that the global state defined by the second operation will always follow the first one.

It is the responsibility of the codex developer to ensure non-ambiguity when this aggregator is used.

§

Nth(StateName, u16)

Takes the nth element of the global state.

Fails if the global state is not defined, i.e., has zero elements, or if the nth-element is empty.

§Nota bene

The global state does not have only a partial ordering (it is a lattice).

It is only in the case when one operation depends on outputs of another (via global or owned state) there is a guarantee that the global state defined by the second operation will always follow the first one.

It is the responsibility of the codex developer to ensure non-ambiguity when this aggregator is used.

§

Last(StateName)

Takes the last element of the global state.

Fails if the global state is not defined, i.e., has zero elements.

§Nota bene

The global state does not have only a partial ordering (it is a lattice).

It is only in the case when one operation depends on outputs of another (via global or owned state) there is a guarantee that the global state defined by the second operation will always follow the first one.

It is the responsibility of the codex developer to ensure non-ambiguity when this aggregator is used.

§

NthBack(StateName, u16)

Takes the nth element of the global state, counting from the end of the list.

Fails if the global state is not defined, i.e., has zero elements, or if the nth-element is empty.

§Nota bene

The global state does not have only a partial ordering (it is a lattice).

It is only in the case when one operation depends on outputs of another (via global or owned state) there is a guarantee that the global state defined by the second operation will always follow the first one.

It is the responsibility of the codex developer to ensure non-ambiguity when this aggregator is used.

§

Neg(StateSelector)

Integer-negate state.

Fails if the state is not defined or contains multiple elements. Also fails if the state is not an unsigned 64-bit integer or is greater than i64::MAX.

§

Add(StateSelector, StateSelector)

Sum two states of different types, expecting them to be integers.

Fails if any of the state is not defined or contains multiple elements. Also fails if the state is not an unsigned 64-bit integer or there is an overflow.

§

Sub(StateSelector, StateSelector)

Substracts the second state from the first state, expecting both to be integers.

Fails if any of the state is not defined or contains multiple elements. Also fails if the state is not an unsigned 64-bit integer or there is an overflow.

§

Mul(StateSelector, StateSelector)

Product two states of different types, expecting them to be integers.

Fails if any of the state is not defined or contains multiple elements. Also fails if the state is not an unsigned 64-bit integer or there is an overflow.

§

Div(StateSelector, StateSelector)

Divide the first state on the second state, expecting them to be integers. The resulting value is rounded towards zero.

Fails if any of the state is not defined or contains multiple elements. Also fails if the state is not an unsigned 64-bit integer, or the second state is zero.

§

Rem(StateSelector, StateSelector)

Modulo-divide the first state on the second state, expecting them to be integers.

Fails if any of the state is not defined or contains multiple elements. Also fails if the state is not an unsigned 64-bit integer, or the second state is zero.

§

Exp(StateSelector, StateSelector)

Exponentiates the first state with the second state, expecting them to be integers. The resulting value is rounded towards zero.

Fails if any of the state is not defined or contains multiple elements. Also fails if the first state is not an unsigned 64-bit integer, the second state is not an unsigned 32-bit integer, or there is an overflow.

§

Count(StateName)

Count the number of elements of the global state of a certain type.

§

CountUnique(StateName)

Count the number of unique elements of the global state of a certain type.

§

SetV(StateName)

Convert a verified state under the same state type into an ordered set.

Acts only on a global state; doesn’t recognize aggregated state.

If the global state with the name is absent returns an empty set.

§

MapV2U(StateName)

Map from a field-based element state to a non-verifiable structured state; when the field-based element state repeats, it is ignored and only the initial state is kept.

The map is sorted by its values, lexicographically.

Acts only on a global state; doesn’t recognize aggregated state.

If the global state with the name is absent returns an empty map.

§Nota bene

The global state does not have only a partial ordering (it is a lattice).

It is only in the case when one operation depends on outputs of another (via global or owned state) there is a guarantee that the global state defined by the second operation will always follow the first one.

It is the responsibility of the codex developer to ensure non-ambiguity when this aggregator is used.

§

MapV2ListU(StateName)

Map from a field-based element state to a list of non-verifiable structured state; when the field-based element state repeats, the list is extended with the non-verifiable state.

The map is ordered according to the global state element order.

Acts only on a global state; doesn’t recognize aggregated state.

If the global state with the name is absent returns an empty map.

§Nota bene

The global state does not have only a partial ordering (it is a lattice).

It is only in the case when one operation depends on outputs of another (via global or owned state) there is a guarantee that the global state defined by the second operation will always follow the first one.

It is the responsibility of the codex developer to ensure non-ambiguity when this aggregator is used.

§

MapV2SetU(StateName)

Map from a field-based element state to a set of non-verifiable structured state; when the field-based element state repeats, the set is extended with the non-verifiable state.

The map is ordered according to the global state element order.

Acts only on a global state; doesn’t recognize aggregated state.

If the global state with the name is absent returns an empty map.

§Nota bene

The global state does not have only a partial ordering (it is a lattice).

It is only in the case when one operation depends on outputs of another (via global or owned state) there is a guarantee that the global state defined by the second operation will always follow the first one.

It is the responsibility of the codex developer to ensure non-ambiguity when this aggregator is used.

§

SumUnwrap(StateName)

Sums over verifiable part of a global state.

Acts only on a global state; doesn’t recognize aggregated state.

Fails if the global state doesn’t have any elements, or if there is an overflow, or the state type is not an unsigned integer.

§

SumOrDefault(StateName)

Sums over verifiable part of a global state.

Acts only on a global state; doesn’t recognize aggregated state.

Produces zero f the global state doesn’t have any elements, or if there is an overflow.

If any of the elements of the global state are not an unsigner integer, treats them as zero.

§

ProdUnwrap(StateName)

Takes a product of the elements of a global state, taking their verifiable part.

Acts only on a global state; doesn’t recognize aggregated state.

Fails if the global state doesn’t have any elements, or if there is an overflow, or the state type is not an unsigned integer.

§

ProdOrDefault(StateName)

Takes a product of the elements of a global state, taking their verifiable part.

Acts only on a global state; doesn’t recognize aggregated state.

Produces zero f the global state doesn’t have any elements, or if there is an overflow.

If any of the elements of the global state are not an unsigner integer, treats them as one.

Implementations§

Source§

impl SubAggregator

Source

pub fn depends_on(&self) -> Vec<&StateName>

Returns names of the other computed state which this aggregator depends on and which needs to be computed before running this aggregator.

Source

pub fn aggregate( &self, global: &BTreeMap<StateName, BTreeMap<CellAddr, StateAtom>>, aggregated: &BTreeMap<StateName, StrictVal>, types: &TypeSystem, ) -> Option<StrictVal>

Compute state via applying some aggregator function.

§Returns

Aggregated state value. If the computing fails due to any exception, None.

Trait Implementations§

Source§

impl Clone for SubAggregator

Source§

fn clone(&self) -> SubAggregator

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 SubAggregator

Source§

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

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

impl<'de> Deserialize<'de> for SubAggregator

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for SubAggregator

Source§

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

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 SubAggregator

Source§

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

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for SubAggregator

Source§

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

Source§

fn partial_cmp(&self, other: &SubAggregator) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for SubAggregator

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

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

impl StrictDecode for SubAggregator

Source§

fn strict_decode(reader: &mut impl TypedRead) -> Result<Self, DecodeError>

Source§

fn strict_read(reader: impl ReadRaw) -> Result<Self, DecodeError>

Source§

impl StrictDumb for SubAggregator

Source§

fn strict_dumb() -> Self

Source§

impl StrictEncode for SubAggregator

Source§

fn strict_encode<W: TypedWrite>(&self, writer: W) -> Result<W>

Source§

fn strict_write(&self, writer: impl WriteRaw) -> Result<(), Error>

Source§

impl StrictSum for SubAggregator

Source§

impl StrictType for SubAggregator

Source§

const STRICT_LIB_NAME: &'static str = LIB_NAME_SONIC

Source§

fn strict_name() -> Option<TypeName>

Source§

impl StrictUnion for SubAggregator

Source§

impl Eq for SubAggregator

Source§

impl StructuralPartialEq for SubAggregator

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> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> 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.
Source§

impl<T> VerifyEq for T
where T: Eq,

Source§

fn verify_eq(&self, other: &T) -> bool

Verifies commit-equivalence of two instances of the same type.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,