pub struct Swap<T>(/* private fields */);Expand description
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);Implementations§
Trait Implementations§
Source§impl<T: Ord> Ord for Swap<T>
impl<T: Ord> Ord for Swap<T>
Source§impl<T: PartialOrd> PartialOrd for Swap<T>
impl<T: PartialOrd> PartialOrd for Swap<T>
impl<T: Copy> Copy for Swap<T>
impl<T: Eq> Eq for Swap<T>
impl<T> StructuralPartialEq for Swap<T>
Auto Trait Implementations§
impl<T> Freeze for Swap<T>where
T: Freeze,
impl<T> RefUnwindSafe for Swap<T>where
T: RefUnwindSafe,
impl<T> Send for Swap<T>where
T: Send,
impl<T> Sync for Swap<T>where
T: Sync,
impl<T> Unpin for Swap<T>where
T: Unpin,
impl<T> UnwindSafe for Swap<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more