pub struct Adapter<'a, T>{ /* private fields */ }Expand description
Wraps a reference to a String representation of some type
The String can be accessed as if it were the type.
An Adapter can be made for any type that implements FromStr and Display.
An Adapter must be dropped before the String can be accessed again.
§Example
use kai::*;
// A `Vec` of number strings
let mut nums: Vec<String> = vec![
"4".into(),
"1".into(),
"-1".into(),
];
// Iterate over `Adapters` that wrap the number strings
// The `Adapter`s can be modified as if they are numbers
for mut n in nums.iter_mut().filter_map(|s| Adapter::<i32>::from(s).ok()) {
*n += 2;
*n *= 2;
}
assert_eq!(
vec!["12".to_string(), "6".into(), "2".into()],
nums,
);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for Adapter<'a, T>where
T: Freeze,
impl<'a, T> RefUnwindSafe for Adapter<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for Adapter<'a, T>where
T: Send,
impl<'a, T> Sync for Adapter<'a, T>where
T: Sync,
impl<'a, T> Unpin for Adapter<'a, T>where
T: Unpin,
impl<'a, T> !UnwindSafe for Adapter<'a, T>
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