Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. struct Schema<F>
  2. where
  3. F: Fn() -> String
  4. {
  5. f: F,
  6. }
  7.  
  8. impl<F> Schema<F>
  9. where
  10. F: Fn() -> String
  11. {
  12. fn new(f: F) -> Self {
  13. Schema { f }
  14. }
  15.  
  16. fn test(&self) {
  17. println!("{}", (self.f)())
  18. }
  19. }
  20.  
  21. fn test() -> String {
  22. "test string".to_string()
  23. }
  24.  
  25. fn range(r: std::ops::Range<usize>) -> impl Fn() -> String {
  26. move || -> String { format!("range() min:{} max:{}", r.start, r.end) }
  27. }
  28.  
  29. fn main() {
  30. let schema = Schema::new(test);
  31. schema.test();
  32.  
  33. let schema = Schema::new(range(1 .. 65000));
  34. schema.test();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement