SHARE
TWEET

Untitled

a guest Mar 25th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::boxed::Box;
  2. use std::ops::Range;
  3.  
  4. struct Schema {
  5.     test: bool,
  6.     testfn: Box<Fn(Range<usize>) -> String>,
  7. }
  8.  
  9. impl Schema {
  10.     fn new<F: 'static>(test_in: F) -> Self
  11.         where F: Fn(Range<usize>) -> String
  12.     {
  13.         Schema{
  14.             test: true,
  15.             testfn: Box::new(test_in),
  16.         }
  17.     }
  18. }
  19.  
  20. fn range_func(r: Range<usize>)->String {
  21.      format!("range() min:{} max:{}",r.start,r.end)
  22. }
  23.  
  24. fn main() {
  25.     println!("Fn range: {}",range_func(0..7));
  26.     let range_closure= |r: Range<usize>| {
  27.        format!("range() min:{} max:{}",r.start,r.end)
  28.     };
  29.     println!("Closure: {}", range_closure(0..7));
  30.     let schema_two = Schema::new(range_closure(0..7));
  31.     //println!("in Box range: {}",(schema_two.testfn)());
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top