[][src]Struct kai::Swap

pub struct Swap<T>(_);

Wrapper that allows consuming transformations on borrowed data

This is useful when you want a mutable interface wrapping a functional one.

Example

use kai::*;

struct Foo {
    v: Swap<Vec<i32>>
}

impl Foo {
    fn keep_even(&mut self) {
        self.v.hold(|v| v.into_iter().filter(|n| n % 2 == 0).collect());
    }
}

let mut foo = Foo { v: vec![1, 2, 3, 4, 5].into() };
foo.keep_even();
assert_eq!(vec![2, 4], *foo.v);

Methods

impl<T> Swap<T>[src]

pub fn new(inner: T) -> Self[src]

Create a new Swap

pub fn hold<F>(&mut self, f: F) where
    F: FnOnce(T) -> T, 
[src]

Take the inner value, transform it, and put it back in place

pub fn into_inner(self) -> T[src]

Take the inner value

Trait Implementations

impl<T: Copy> Copy for Swap<T>[src]

impl<T: PartialEq> PartialEq<Swap<T>> for Swap<T>[src]

impl<T> AsRef<T> for Swap<T>[src]

impl<T> Default for Swap<T> where
    T: Default
[src]

impl<T: Clone> Clone for Swap<T>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Ord> Ord for Swap<T>[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<T> From<T> for Swap<T>[src]

impl<T: Eq> Eq for Swap<T>[src]

impl<T: PartialOrd> PartialOrd<Swap<T>> for Swap<T>[src]

impl<T> DerefMut for Swap<T>[src]

impl<T> Deref for Swap<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T> Display for Swap<T> where
    T: Display
[src]

impl<T> Debug for Swap<T> where
    T: Debug
[src]

impl<T: Hash> Hash for Swap<T>[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<T> Borrow<T> for Swap<T>[src]

Auto Trait Implementations

impl<T> Send for Swap<T> where
    T: Send

impl<T> Sync for Swap<T> where
    T: Sync

Blanket Implementations

impl<T> Bind for T[src]

fn bind_mut<F>(self, f: F) -> Self where
    F: FnMut(&mut Self), 
[src]

Binds the value, mutates it, and returns it

fn bind_map<F, R>(self, f: F) -> R where
    F: FnMut(Self) -> R, 
[src]

Binds the value, maps it with the function, and returns the mapped value

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]