Why Not Closures

  • Closures don't hold much contextual information (for humans).
  • Similar to stringly-typed instead of strongly typed.

Closure:

// Trait:
// Fn(&Block, &Block) -> &Block;

// Implementation
let cipher_chain: Box<dyn Fn(&Block, &Block) -> &Block> =
    Box::new(|block_current, block_previous| -> Block { /* .. */ });

Trait:


#![allow(unused_variables)]
fn main() {
/// Chain of encrypted block data.
pub trait CipherChain {
    /// The type of the block.
    type Block;

    /// Returns encrypted block data.
    ///
    /// # Parameters
    ///
    /// * `block_current`: Block to encrypt.
    /// * `block_previous`: Previous encrypted block.
    fn compute(block_current: &Self::Block, block_previous: &Self::Block) -> Self::Block;
}
}