SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. trait FnLt<'a> {
  2.     fn apply(self, input: &'a u8) -> &'a u8;
  3. }
  4.  
  5. // Struct impl
  6. struct Foo;
  7. impl<'a> FnLt<'a> for Foo {
  8.     fn apply(self, input: &'a u8) -> &'a u8 {
  9.         input
  10.     }
  11. }
  12.  
  13. // Closure impl
  14. impl<'a, T> FnLt<'a> for T
  15. where
  16.     T: FnOnce(&'a u8) -> &'a u8,
  17. {
  18.     fn apply(self, input: &'a u8) -> &'a u8 {
  19.         (self)(input)
  20.     }
  21. }
  22.  
  23. fn take_fn_lt(_: impl for<'a> FnLt<'a>) {}
  24.  
  25. fn fix<F: FnOnce(&u8) -> &u8>(x: F) -> F {
  26.     x
  27. }
  28.  
  29. fn main() {
  30.     take_fn_lt(Foo); // Works
  31.    
  32.     fn foo(x: &u8) -> &u8 { x }
  33.     take_fn_lt(foo); // Works
  34.    
  35.     //take_fn_lt(|x: &u8| -> &u8 { x }); // Doesn't work
  36.     take_fn_lt(fix(|x: &u8| -> &u8 { x })); // Doesn work
  37. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top