Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused)]
- extern crate either; // 1.5.1
- use either::Either;
- use std::fs;
- trait B {
- fn bounded_box(self) -> f32;
- }
- trait C {
- fn bounded_box(self) -> f32;
- }
- impl B for f64 {
- fn bounded_box(self) -> f32 {
- return 2.0;
- }
- }
- impl C for f32 {
- fn bounded_box(self) -> f32 {
- return 1.0;
- }
- }
- fn interact<T: B, U: C>(x: Either<T, U>) -> f32 {
- match x {
- Either::Left(v) => v.bounded_box(),
- Either::Right(v) => v.bounded_box(),
- }
- }
- fn main() {
- println!("{}", interact::<f64, f32>(Either::Right(1.0f32)));
- println!("{}", interact::<f64, f32>(Either::Left(1.0f64)));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement