[−][src]Struct kai::Swap
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]
F: FnOnce(T) -> T,
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: Clone> Clone for Swap<T>
[src]
fn clone(&self) -> Swap<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: PartialEq> PartialEq<Swap<T>> for Swap<T>
[src]
impl<T: PartialOrd> PartialOrd<Swap<T>> for Swap<T>
[src]
fn partial_cmp(&self, other: &Swap<T>) -> Option<Ordering>
[src]
fn lt(&self, other: &Swap<T>) -> bool
[src]
fn le(&self, other: &Swap<T>) -> bool
[src]
fn gt(&self, other: &Swap<T>) -> bool
[src]
fn ge(&self, other: &Swap<T>) -> bool
[src]
impl<T: Eq> Eq for Swap<T>
[src]
impl<T: Ord> Ord for Swap<T>
[src]
fn cmp(&self, other: &Swap<T>) -> Ordering
[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
impl<T: Copy> Copy for Swap<T>
[src]
impl<T> AsRef<T> for Swap<T>
[src]
impl<T> From<T> for Swap<T>
[src]
impl<T> Default for Swap<T> where
T: Default,
[src]
T: Default,
impl<T> Display for Swap<T> where
T: Display,
[src]
T: Display,
impl<T> Debug for Swap<T> where
T: Debug,
[src]
T: Debug,
impl<T> Deref for Swap<T>
[src]
impl<T> DerefMut for Swap<T>
[src]
impl<T: Hash> Hash for Swap<T>
[src]
fn hash<__HT: Hasher>(&self, state: &mut __HT)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T> Borrow<T> for Swap<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Bind for T
[src]
fn bind_mut<F>(self, f: F) -> Self where
F: FnMut(&mut Self),
[src]
F: FnMut(&mut Self),
Binds the value, mutates it, and returns it
fn bind_map<F, R>(self, f: F) -> R where
F: FnMut(Self) -> R,
[src]
F: FnMut(Self) -> R,
Binds the value, maps it with the function, and returns the mapped value
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Rfn borrow_mut(&mut self) -> &mut T
[src]
ⓘImportant traits for &'_ mut R
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,