Struct puffin::algebra::term::Term

source ·
pub struct Term<PT: ProtocolTypes> {
    pub term: DYTerm<PT>,
    pub payloads: Option<Payloads>,
}
Expand description

Terms are Terms equipped with optional Payloads when they no longer are treated as symbolic terms.

Fields§

§term: DYTerm<PT>§payloads: Option<Payloads>

Implementations§

source§

impl<PT: ProtocolTypes> Term<PT>

source

pub(crate) fn eval_until_opaque<PB>( &self, eval_tree: &mut EvalTree, ctx: &TraceContext<PB>, with_payloads: bool, sibling_has_payloads: bool, type_term: &TypeShape<PT>, ) -> Result<(Box<dyn EvaluatedTerm<PT>>, Vec<PayloadContext<'_, PT>>), Error>
where PB: ProtocolBehavior<ProtocolTypes = PT>,

Evaluate a term without replacing the payloads (returning the payloads with the corresponding paths instead, i.e., a Vec<PayloadContext> accumulator), except when reaching an opaque term with payloads as strict sub-terms. In the latter case, fully evaluate each of the arguments (and performing the payload replacements) before evaluating the opaque function, which then needs to be read to convert it back to a Box<dyn EvaluatedTerm<PT>>. @path: current path of &self in the overall recipe (initially []). Invariant: Returns the payloads to replace in this order: deeper first, left-most arguments first. When with_payloads is false, then this should be equivalent to evaluate_lazy_test and it always return empty PayloadContext vectors.

source§

impl<PT: ProtocolTypes> Term<PT>

source

pub fn height(&self) -> usize

Height of term, considering non-symbolic terms as atoms

source

pub fn is_list(&self) -> bool

When the term starts with a list function symbol

source

pub fn is_opaque(&self) -> bool

When the term starts with an opaque function symbol (like encryption)

source

pub fn erase_payloads_subterms(&mut self, is_subterm: bool)

Erase all payloads in a term, including those under opaque function symbol

source

pub fn add_payload(&mut self, payload: Vec<u8>)

Add a payload at the root position, erase payloads in strict sub-terms not under opaque

source

pub fn make_payload<PB>(&mut self, ctx: &TraceContext<PB>) -> Result<(), Error>
where PB: ProtocolBehavior<ProtocolTypes = PT>,

Make and Add a payload at the root position, erase payloads in strict sub-terms not under opaque

source

pub fn all_payloads(&self) -> Vec<&Payloads>

Return all payloads contains in a term, even under opaque terms. Note that we keep the invariant that a non-symbolic term cannot have payloads in struct-subterms, see add_payload/make_payload.

source

pub fn all_payloads_mut(&mut self) -> Vec<&mut Payloads>

Return all payloads contains in a term (mutable references), even under opaque terms. Note that we keep the invariant that a non-symbolic term cannot have payloads in struct-subterms, see add_payload/make_payload.

source

pub fn payloads_to_replace(&self) -> Vec<&Payloads>

Return all payloads contained in a term, except those under opaque terms. The deeper the first in the returned vector.

source

pub fn has_payload_to_replace(&self) -> bool

Return whether there is at least one payload, except those under opaque terms.

source

pub fn has_payload_to_replace_wo_root(&self) -> bool

Return whether there is at least one payload, except those under opaque terms and at the root..

source§

impl<PT: ProtocolTypes> Term<PT>

source

fn unique_id(&self, tree_mode: bool, cluster_id: usize) -> String

source

fn node_attributes( displayable: impl Display, color: &str, shape: &str, ) -> String

source

fn collect_statements( term: &Self, tree_mode: bool, cluster_id: usize, statements: &mut Vec<String>, )

source

pub fn dot_subgraph( &self, tree_mode: bool, cluster_id: usize, label: &str, ) -> String

If tree_mode is true then each subgraph is self-contained and does not reference other clusters or nodes outside of this subgraph. Therefore, only trees are generated. If it is false, then graphs are rendered.

source§

impl<PT: ProtocolTypes> Term<PT>

source

pub fn count_functions_by_name(&self, find_name: &'static str) -> usize

Trait Implementations§

source§

impl<PT: Clone + ProtocolTypes> Clone for Term<PT>

source§

fn clone(&self) -> Term<PT>

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<PT: Debug + ProtocolTypes> Debug for Term<PT>

source§

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

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

impl<'de, PT> Deserialize<'de> for Term<PT>
where PT: ProtocolTypes,

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<PT: ProtocolTypes> Display for Term<PT>

source§

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

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

impl<PT: ProtocolTypes> From<DYTerm<PT>> for Term<PT>

source§

fn from(term: DYTerm<PT>) -> Self

Converts to this type from the input type.
source§

impl<PT: ProtocolTypes> From<Term<PT>> for DYTerm<PT>

source§

fn from(term: Term<PT>) -> Self

Converts to this type from the input type.
source§

impl<PT: Hash + ProtocolTypes> Hash for Term<PT>

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<'a, PT: ProtocolTypes> IntoIterator for &'a Term<PT>

source§

type IntoIter = IntoIter<&'a Term<PT>>

Which kind of iterator are we turning this into?
source§

type Item = &'a Term<PT>

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<PT: PartialEq + ProtocolTypes> PartialEq for Term<PT>

source§

fn eq(&self, other: &Term<PT>) -> 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<PT> Serialize for Term<PT>
where PT: ProtocolTypes,

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<PT: ProtocolTypes> Subterms<PT, Term<PT>> for Vec<Term<PT>>

source§

fn find_subterm_same_shape(&self, term: &Term<PT>) -> Option<&Term<PT>>

Finds a subterm with the same type as term

source§

fn find_subterm<P: Fn(&&Term<PT>) -> bool + Copy>( &self, predicate: P, ) -> Option<&Term<PT>>

Finds a subterm in this vector

source§

fn filter_grand_subterms<P: Fn(&Term<PT>, &Term<PT>) -> bool + Copy>( &self, predicate: P, ) -> Vec<((usize, &Term<PT>), &Term<PT>)>

Finds all grand children/subterms which match the predicate.

A grand subterm is defined as a subterm of a term in self.

Each grand subterm is returned together with its parent and the index of the parent in self.

source§

impl<PT: ProtocolTypes> TermType<PT> for Term<PT>

source§

fn evaluate_config<PB>( &self, context: &TraceContext<PB>, with_payloads: bool, ) -> Result<(ConcreteMessage, Box<dyn EvaluatedTerm<PT>>), Error>
where PB: ProtocolBehavior<ProtocolTypes = PT> + ProtocolBehavior,

Evaluate terms into bitstrings and EvaluatedTerm (considering Payloads)

source§

fn size(&self) -> usize

size of a term, considering non-symbolic terms as atoms

source§

fn resistant_id(&self) -> u32

source§

fn is_leaf(&self) -> bool

source§

fn get_type_shape(&self) -> &TypeShape<PT>

source§

fn name(&self) -> &str

source§

fn mutate(&mut self, other: Self)

source§

fn display_at_depth(&self, depth: usize) -> String

source§

fn is_symbolic(&self) -> bool

source§

fn make_symbolic(&mut self)

source§

fn evaluate<PB>(&self, ctx: &TraceContext<PB>) -> Result<ConcreteMessage, Error>
where PB: ProtocolBehavior<ProtocolTypes = PT> + ProtocolBehavior,

Evaluate terms into ConcreteMessage (considering Payloads)
source§

fn evaluate_symbolic<PB>( &self, ctx: &TraceContext<PB>, ) -> Result<ConcreteMessage, Error>
where PB: ProtocolBehavior<ProtocolTypes = PT> + ProtocolBehavior,

Evaluate terms into ConcreteMessage considering all sub-terms as symbolic (even those with Payloads)
source§

fn evaluate_dy<PB>( &self, ctx: &TraceContext<PB>, ) -> Result<Box<dyn EvaluatedTerm<PT>>, Error>
where PB: ProtocolBehavior<ProtocolTypes = PT> + ProtocolBehavior,

Evaluate terms into EvaluatedTerm considering all sub-terms as symbolic (even those with Payloads)
source§

impl<PT: Eq + ProtocolTypes> Eq for Term<PT>

source§

impl<PT: ProtocolTypes> StructuralPartialEq for Term<PT>

Auto Trait Implementations§

§

impl<PT> Freeze for Term<PT>
where <PT as ProtocolTypes>::Matcher: Freeze,

§

impl<PT> !RefUnwindSafe for Term<PT>

§

impl<PT> Send for Term<PT>
where PT: Send, <PT as ProtocolTypes>::Matcher: Send,

§

impl<PT> Sync for Term<PT>
where PT: Sync, <PT as ProtocolTypes>::Matcher: Sync,

§

impl<PT> Unpin for Term<PT>
where PT: Unpin, <PT as ProtocolTypes>::Matcher: Unpin,

§

impl<PT> !UnwindSafe for Term<PT>

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> AsAny for T
where T: 'static,

source§

fn as_any(&self) -> &(dyn Any + 'static)

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
§

impl<T> CloneAny for T
where T: Any + Clone + Send + Sync,

§

fn clone_any(&self) -> Box<dyn CloneAny>

§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>

§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>

§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Sync + Send>

source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> DynClone for T
where T: Clone,

§

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

§

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.

§

impl<Tail, T> Prepend<T> for Tail

§

type PreprendResult = Tail

The Resulting [TupleList], of an [Prepend::prepend()] call, including the prepended entry.
§

fn prepend(self, value: T) -> (T, <Tail as Prepend<T>>::PreprendResult)

Prepend a value to this tuple, returning a new tuple with prepended value.
source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> DebugAny for T
where T: Any + Debug,

source§

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

§

impl<T> MaybeHasScalabilityMonitor for T

§

impl<T> UnsafeAny for T
where T: Any,