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
impl SubAggregator
Sourcepub fn depends_on(&self) -> Vec<&StateName> ⓘ
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.
Sourcepub fn aggregate(
&self,
global: &BTreeMap<StateName, BTreeMap<CellAddr, StateAtom>>,
aggregated: &BTreeMap<StateName, StrictVal>,
types: &TypeSystem,
) -> Option<StrictVal>
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
impl Clone for SubAggregator
Source§fn clone(&self) -> SubAggregator
fn clone(&self) -> SubAggregator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SubAggregator
impl Debug for SubAggregator
Source§impl<'de> Deserialize<'de> for SubAggregator
impl<'de> Deserialize<'de> for SubAggregator
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Hash for SubAggregator
impl Hash for SubAggregator
Source§impl Ord for SubAggregator
impl Ord for SubAggregator
Source§fn cmp(&self, other: &SubAggregator) -> Ordering
fn cmp(&self, other: &SubAggregator) -> 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 SubAggregator
impl PartialEq for SubAggregator
Source§impl PartialOrd for SubAggregator
impl PartialOrd for SubAggregator
Source§impl Serialize for SubAggregator
impl Serialize for SubAggregator
Source§impl StrictDecode for SubAggregator
impl StrictDecode for SubAggregator
fn strict_decode(reader: &mut impl TypedRead) -> Result<Self, DecodeError>
fn strict_read(reader: impl ReadRaw) -> Result<Self, DecodeError>
Source§impl StrictDumb for SubAggregator
impl StrictDumb for SubAggregator
fn strict_dumb() -> Self
Source§impl StrictEncode for SubAggregator
impl StrictEncode for SubAggregator
fn strict_encode<W: TypedWrite>(&self, writer: W) -> Result<W>
fn strict_write(&self, writer: impl WriteRaw) -> Result<(), Error>
Source§impl StrictSum for SubAggregator
impl StrictSum for SubAggregator
const ALL_VARIANTS: &'static [(u8, &'static str)]
fn variant_name(&self) -> &'static str
fn strict_check_variants()
fn variant_name_by_tag(tag: u8) -> Option<VariantName>
fn variant_ord(&self) -> u8
Source§impl StrictType for SubAggregator
impl StrictType for SubAggregator
const STRICT_LIB_NAME: &'static str = LIB_NAME_SONIC
fn strict_name() -> Option<TypeName>
Source§impl StrictUnion for SubAggregator
impl StrictUnion for SubAggregator
fn strict_type_info() -> TypeInfo<Self>
impl Eq for SubAggregator
impl StructuralPartialEq for SubAggregator
Auto Trait Implementations§
impl Freeze for SubAggregator
impl RefUnwindSafe for SubAggregator
impl Send for SubAggregator
impl Sync for SubAggregator
impl Unpin for SubAggregator
impl UnwindSafe for SubAggregator
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§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.