[−][src]Struct kai::Adapter
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, );
Methods
impl<'a, T> Adapter<'a, T> where
T: FromStr + Display,
[src]
T: FromStr + Display,
pub fn from(string: &'a mut String) -> Result<Adapter<'a, T>, T::Err>
[src]
Create a new Adapter
from a String
pub fn finish(self)
[src]
Force a drop, returning ownership to the string
This function only needs to be called if you want access to the string
before the Adapter
would normally be dropped.
Trait Implementations
impl<'a, T> Drop for Adapter<'a, T> where
T: FromStr + Display,
[src]
T: FromStr + Display,
impl<'a, T> AsRef<T> for Adapter<'a, T> where
T: FromStr + Display,
[src]
T: FromStr + Display,
impl<'a, T> DerefMut for Adapter<'a, T> where
T: FromStr + Display,
[src]
T: FromStr + Display,
impl<'a, T> Deref for Adapter<'a, T> where
T: FromStr + Display,
[src]
T: FromStr + Display,
impl<'a, T> Display for Adapter<'a, T> where
T: FromStr + Display,
[src]
T: FromStr + Display,
impl<'a, T> Debug for Adapter<'a, T> where
T: FromStr + Display + Debug,
[src]
T: FromStr + Display + Debug,
impl<'a, T> Borrow<T> for Adapter<'a, T> where
T: FromStr + Display,
[src]
T: FromStr + Display,
Auto Trait Implementations
impl<'a, T> Send for Adapter<'a, T> where
T: Send,
T: Send,
impl<'a, T> Sync for Adapter<'a, T> where
T: Sync,
T: Sync,
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, 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, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,