Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. use std::{convert::Infallible, future::Future};
  2.  
  3. trait Trait {}
  4.  
  5. impl<Fut> Trait for fn(&u8, &u16) -> Fut where Fut: Future<Output = Result<(), Infallible>> {}
  6.  
  7. async fn lol(_: &u8, _: &u16) -> Result<(), Infallible> {
  8. Ok(())
  9. }
  10.  
  11. fn check<T: Trait>(_: T) {}
  12.  
  13. pub fn check2() {
  14. let f = coerce_to_fn_ptr(lol as AsyncFn<_>);
  15. //check()
  16. }
  17.  
  18. type AsyncFn<Fut>
  19. where
  20. Fut: Future<Output = Result<(), Infallible>>,
  21. = fn(&u8, &u16) -> Fut;
  22.  
  23. #[inline]
  24. fn coerce_to_fn_ptr<Fut>(f: AsyncFn<Fut>) -> AsyncFn<Fut>
  25. where
  26. Fut: Future<Output = Result<(), Infallible>>,
  27. {
  28. f
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement