Trait Poppable

Source
pub trait Poppable: TupleLike {
    type PopFrontOutput: TupleLike;
    type PopFrontElement;
    type PopBackOutput: TupleLike;
    type PopBackElement;

    // Required methods
    fn pop(self) -> (Self::PopBackOutput, Self::PopBackElement);
    fn pop_front(self) -> (Self::PopFrontOutput, Self::PopFrontElement);

    // Provided method
    fn pop_back(self) -> (Self::PopBackOutput, Self::PopBackElement)
       where Self: Sized { ... }
}
Expand description

Pop elements from the front and back of the tuple.

The Unit type is not Poppable. All Tuples are Poppable.

The take! macro provides another way to take out elements by their indices or types.

Required Associated Types§

Source

type PopFrontOutput: TupleLike

The type of tuple generated by popping an element from the front of the tuple.

Source

type PopFrontElement

The type of the element popped from the front of the tuple.

Source

type PopBackOutput: TupleLike

The type of tuple generated by popping an element from the back of the tuple.

Source

type PopBackElement

The type of the element popped from the back of the tuple.

Required Methods§

Source

fn pop(self) -> (Self::PopBackOutput, Self::PopBackElement)

Pop an element from the back of the tuple.

Hint: The TupleLike trait provides the pop() method as the wrapper for this pop() method.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
let (tup2, popped) = tup.pop();
assert_eq!(tup2, tuple!(1, "hello"));
assert_eq!(popped, 3.14);
Source

fn pop_front(self) -> (Self::PopFrontOutput, Self::PopFrontElement)

Pop an element from the front of the tuple.

Hint: The TupleLike trait provides the pop_front() method as the wrapper for this pop_front() method.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
let (tup2, popped) = tup.pop_front();
assert_eq!(tup2, tuple!("hello", 3.14));
assert_eq!(popped, 1);

Provided Methods§

Source

fn pop_back(self) -> (Self::PopBackOutput, Self::PopBackElement)
where Self: Sized,

Pop an element from the back of the tuple. Same as pop().

Hint: The TupleLike trait provides the pop_back() method as the wrapper for this pop_back() method.

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<First> Poppable for Tuple<First, Unit>

Source§

impl<First, Other> Poppable for Tuple<First, Other>
where Other: Poppable,