[][src]Struct char_circle::SimpleStringTransform

pub struct SimpleStringTransform<T>(pub PhantomData<T>);

Used when you have a SimpleTransform but need a StringTransform.

Example

// `Identity` is a `SimpleTransform`.
struct Identity<I>(I);

impl<I: Iterator<Item=char>> Iterator for Identity<I> {
    type Item = char;
    fn next(&mut self) -> Option<char> {
        self.0.next()
    }
}

impl<'a> SimpleTransform<'a> for Identity<Chars<'a>> {
    fn transform_chars(chars: Chars<'a>) -> Self {
        Identity(chars)
    }
}

// This function takes a `StringTransform`.
fn apply_transform<'a, T: StringTransform<'a>>(t: T, s: String) -> String {
    t.transform(s).into_owned()
}

// Use `SimpleStringTransform` to bridge the gap.
let t = SimpleStringTransform::<Identity<Chars>>::new();
let s = apply_transform(t, "Hello World".to_string());
assert_eq!(&s, "Hello World");

Methods

impl<'a, T: SimpleTransform<'a>> SimpleStringTransform<T>[src]

pub fn new() -> Self[src]

Create a new SimpleStringTransform.

Trait Implementations

impl<'a, T: SimpleTransform<'a>> StringTransform<'a> for SimpleStringTransform<T>[src]

type Iter = T

The type after applying this transform to a Chars iterator.

fn transform<'b, T: Into<Cow<'b, str>>>(&self, s: T) -> Cow<'b, str>[src]

Transform a string in-place Read more

Auto Trait Implementations

impl<T> Send for SimpleStringTransform<T> where
    T: Send

impl<T> Sync for SimpleStringTransform<T> where
    T: Sync

Blanket Implementations

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> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

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.