Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this compiles
- fn validator<F, T>(f: F) -> Box<Fn(String) -> Result<(), String> + 'static>
- where F: Fn(String) -> Result<T, String> + 'static {
- Box::new(move |s| f(s).map(|_| ()))
- }
- // this fails with:
- // error[E0308]: mismatched types
- // --> src\main.rs:17:14
- // |
- // 17 | Box::new(move |s| f(s).map(|_| ()))
- // | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter, found closure
- // |
- // = note: expected type `G`
- // found type `[closure@src\main.rs:17:14: 17:39 f:_]`
- //
- // error: aborting due to previous error
- //
- // For more information about this error, try `rustc --explain E0308`.
- fn validator_bad<F, G, T>(f: F) -> Box<G>
- where F: Fn(String) -> Result<T, String> + 'static,
- G: Fn(String) -> Result<(), String> + 'static {
- Box::new(move |s| f(s).map(|_| ()))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement