Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. // this compiles
  2. fn validator<F, T>(f: F) -> Box<Fn(String) -> Result<(), String> + 'static>
  3. where F: Fn(String) -> Result<T, String> + 'static {
  4. Box::new(move |s| f(s).map(|_| ()))
  5. }
  6.  
  7. // this fails with:
  8. // error[E0308]: mismatched types
  9. // --> src\main.rs:17:14
  10. // |
  11. // 17 | Box::new(move |s| f(s).map(|_| ()))
  12. // | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter, found closure
  13. // |
  14. // = note: expected type `G`
  15. // found type `[closure@src\main.rs:17:14: 17:39 f:_]`
  16. //
  17. // error: aborting due to previous error
  18. //
  19. // For more information about this error, try `rustc --explain E0308`.
  20. fn validator_bad<F, G, T>(f: F) -> Box<G>
  21. where F: Fn(String) -> Result<T, String> + 'static,
  22. G: Fn(String) -> Result<(), String> + 'static {
  23. Box::new(move |s| f(s).map(|_| ()))
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement