Trait puffin::algebra::dynamic_function::DynamicFunction

source ·
pub trait DynamicFunction<PT: ProtocolTypes>:
    Fn(&Vec<Box<dyn EvaluatedTerm<PT>>>) -> Result<Box<dyn EvaluatedTerm<PT>>, FnError>
    + Send
    + Sync {
    // Required method
    fn clone_box(&self) -> Box<dyn DynamicFunction<PT>>;
}
Expand description

Cloneable type for dynamic functions. This trait is automatically implemented for arbitrary closures and functions of the form: Fn(&Vec<Box<dyn Any>>) -> Box<dyn Any>

Clone is implemented for Box<dyn DynamicFunction> using this trick: https://users.rust-lang.org/t/how-to-clone-a-boxed-closure/31035/25

We want to use Any here and not VariableData (which implements Clone). Else all returned types in functions op_impl.rs would need to return a cloneable struct. Message for example is not.

Required Methods§

source

fn clone_box(&self) -> Box<dyn DynamicFunction<PT>>

Trait Implementations§

source§

impl<PT: ProtocolTypes> Clone for Box<dyn DynamicFunction<PT>>

source§

fn clone(&self) -> Self

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: ProtocolTypes> Debug for Box<dyn DynamicFunction<PT>>

source§

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

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

impl<PT: ProtocolTypes> Display for Box<dyn DynamicFunction<PT>>

source§

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

Formats the value using the given formatter. Read more

Implementors§

source§

impl<F, PT: ProtocolTypes> DynamicFunction<PT> for F
where F: 'static + Fn(&Vec<Box<dyn EvaluatedTerm<PT>>>) -> Result<Box<dyn EvaluatedTerm<PT>>, FnError> + Clone + Send + Sync,