Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #![allow(unused)]
  2. extern crate either; // 1.5.1
  3. use either::Either;
  4. use std::fs;
  5.  
  6. trait B {
  7. fn bounded_box(self) -> f32;
  8. }
  9.  
  10. trait C {
  11. fn bounded_box(self) -> f32;
  12. }
  13.  
  14. impl B for f64 {
  15. fn bounded_box(self) -> f32 {
  16. return 2.0;
  17. }
  18. }
  19.  
  20. impl C for f32 {
  21. fn bounded_box(self) -> f32 {
  22. return 1.0;
  23. }
  24. }
  25.  
  26. fn interact<T: B, U: C>(x: Either<T, U>) -> f32 {
  27. match x {
  28. Either::Left(v) => v.bounded_box(),
  29. Either::Right(v) => v.bounded_box(),
  30. }
  31. }
  32.  
  33. fn main() {
  34. println!("{}", interact::<f64, f32>(Either::Right(1.0f32)));
  35. println!("{}", interact::<f64, f32>(Either::Left(1.0f64)));
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement