Stack

Trait Stack 

Source
pub trait Stack {
    type Remaining: Stack;
    type Head;

    // Required methods
    fn pop(self) -> (Self::Remaining, Self::Head);
    fn push<H>(self, head: H) -> Cons<Self, H>
       where Self: Sized;
    fn map<F: FnOnce(&Self::Head) -> O, O>(&self, f: F) -> O;
    fn map_remaining<F: FnOnce(&Self::Remaining) -> O, O>(&self, f: F) -> O;
    fn take_map<F: FnOnce(Self::Head) -> Result<(Self::Head, O), E>, O, E>(
        self,
        f: F,
    ) -> Result<(Self, O), E>
       where Self: Sized;
    fn map_mut<F: FnOnce(&mut Self::Head) -> O, O>(&mut self, f: F) -> O;
}
Expand description

Trait that defines a stack to store the results computed by forward propagation when training a neural network.

Required Associated Types§

Source

type Remaining: Stack

Stack containing elements that do not include the top element of the stack

Source

type Head

Top element of the stack

Required Methods§

Source

fn pop(self) -> (Self::Remaining, Self::Head)

Returns a tuple of the top item in the stack and the rest of the stack

Source

fn push<H>(self, head: H) -> Cons<Self, H>
where Self: Sized,

Returns Cons with items pushed to the stack

§Arguments
  • head - Items to be added
Source

fn map<F: FnOnce(&Self::Head) -> O, O>(&self, f: F) -> O

Returns the result of applying the callback function to the top element of the stack

§Arguments
  • f - Applicable callbacks
Source

fn map_remaining<F: FnOnce(&Self::Remaining) -> O, O>(&self, f: F) -> O

Returns the result of applying the callback to a stack that does not contain the top element of the stack

  • f - Applicable callbacks
Source

fn take_map<F: FnOnce(Self::Head) -> Result<(Self::Head, O), E>, O, E>( self, f: F, ) -> Result<(Self, O), E>
where Self: Sized,

Returns the result of taking ownership of the first element of the stack and applying the callback function.

§Arguments
  • f - Applicable callbacks
Source

fn map_mut<F: FnOnce(&mut Self::Head) -> O, O>(&mut self, f: F) -> O

Pass a mutable reference to the top element of the stack to the callback function and return the result of executing it

§Arguments
  • f - Applicable callbacks

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Stack for Nil

Source§

impl<R, T> Stack for Cons<R, T>
where R: Stack,