Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. use std::convert::TryInto;
  2.  
  3. trait GenericTryInto {
  4. fn try_into_gen<T>(self) -> Result<T, Self::Error> where Self: TryInto<T> {
  5. self.try_into()
  6. }
  7. }
  8. impl<T: ?Sized> GenericTryInto for T {}
  9.  
  10. fn foo(x: u32) {
  11. let x = x.try_into_gen::<u8>().expect("Not a u8");
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement