Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. pub fn identity(s: &str) -> &str {
  2. s
  3. }
  4.  
  5. pub fn apply1<F>(v: &str, f: F) -> &str where F: Fn(&str) -> &str {
  6. f(v)
  7. }
  8.  
  9. pub fn apply2<T, R, F>(v: T, f: F) -> R where F: Fn(T) -> R {
  10. f(v)
  11. }
  12.  
  13. #[test]
  14. pub fn test_apply1() {
  15. assert_eq!("test", apply1("test", identity));
  16. }
  17.  
  18. #[test]
  19. pub fn test_apply2() {
  20. assert_eq!("test", apply2("test", identity));
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement