pub struct SimpleStringTransform<T>(pub PhantomData<T>);
Expand description
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");
Tuple Fields§
§0: PhantomData<T>
Implementations§
Source§impl<'a, T: SimpleTransform<'a>> SimpleStringTransform<T>
impl<'a, T: SimpleTransform<'a>> SimpleStringTransform<T>
Trait Implementations§
Source§impl<'a, T: SimpleTransform<'a>> StringTransform<'a> for SimpleStringTransform<T>
impl<'a, T: SimpleTransform<'a>> StringTransform<'a> for SimpleStringTransform<T>
Auto Trait Implementations§
impl<T> Freeze for SimpleStringTransform<T>
impl<T> RefUnwindSafe for SimpleStringTransform<T>where
T: RefUnwindSafe,
impl<T> Send for SimpleStringTransform<T>where
T: Send,
impl<T> Sync for SimpleStringTransform<T>where
T: Sync,
impl<T> Unpin for SimpleStringTransform<T>where
T: Unpin,
impl<T> UnwindSafe for SimpleStringTransform<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