[][src]Struct kai::Adapter

pub struct Adapter<'a, T> where
    T: FromStr + Display
{ /* fields omitted */ }

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]

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]

impl<'a, T> AsRef<T> for Adapter<'a, T> where
    T: FromStr + Display
[src]

impl<'a, T> DerefMut for Adapter<'a, T> where
    T: FromStr + Display
[src]

impl<'a, T> Deref for Adapter<'a, T> where
    T: FromStr + Display
[src]

type Target = T

The resulting type after dereferencing.

impl<'a, T> Display for Adapter<'a, T> where
    T: FromStr + Display
[src]

impl<'a, T> Debug for Adapter<'a, T> where
    T: FromStr + Display + Debug
[src]

impl<'a, T> Borrow<T> for Adapter<'a, T> where
    T: FromStr + Display
[src]

Auto Trait Implementations

impl<'a, T> Send for Adapter<'a, T> where
    T: Send

impl<'a, T> Sync for Adapter<'a, 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> 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]