Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement