SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::convert::{TryFrom, TryInto};
  2. use num_traits::cast::AsPrimitive;
  3.  
  4. struct Numeric(u64);
  5.  
  6. enum SomeType {
  7.   Numeric(Numeric),
  8. }
  9.  
  10. impl<T: Into<u64>> From<T> for SomeType {
  11.     fn from(n: T) -> Self {
  12.         SomeType::Numeric(Numeric(n.into()))
  13.     }
  14. }
  15. fn main() {
  16.     let x: SomeType = 0u8.try_into().unwrap();
  17. }
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