impl Trait in Rust explanation

fn apply<A, B, C, F, G>(mut f: F, a: A) 
-> impl FnMut(&B) -> C
where F: FnMut(B) -> G,
G: FnMut(A) -> C,
B: Copy,
A: Clone {
move |b| f(*b)(a.clone())
}
fn apply<A, B, C, G>(mut f: impl FnMut(B) -> G, a: A)
-> impl FnMut(&B) -> C
where
G: FnMut(A) -> C,
B: Copy,
A: Clone {
move |b| f(*b)(a.clone())
}
fn apply<A, B, C>(mut f: impl FnMut(B) -> impl FnMut(A) -> C, a: A)
-> impl FnMut(&B) -> C
where
B: Copy,
A: Clone {

move |b| f(*b)(a.clone())
}
fn accumulate<'a, T>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> T
where T: Monoid + From<&'a str> + From<String> {
...
}
fn accumulate<'a>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> impl Monoid + From<&'a str> + From<String> {

...
}
pub fn fizzbuzz<'a>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> String {
accumulate(tuples, i)
}

pub fn cowbuzz<'a>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> Cow<'a, str> {
accumulate(tuples, i)
}
fn accumulate<'a>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> any Monoid + From<&'a str> + From<String> {

...
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Igor Polyakov

Igor Polyakov

More from Medium

LCM reduction of an Array.

Leaf Traversal | Rust

Testing in Rust

Mocking Time in Async Rust