Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. use std::ops::Add;
  2.  
  3. trait Scalar: Sized
  4. where
  5. f64: Add<Self, Output = Self>,
  6. {}
  7.  
  8. impl Scalar for f64 {}
  9.  
  10. fn add_one<S>(a: S) -> S
  11. where
  12. S: Scalar,
  13. f64: Add<S, Output = S>, // Why is this line necessary?
  14. {
  15. 1.0 + a
  16. }
  17.  
  18. fn main() {
  19. println!("1 + 1 = {}", add_one(1.0));
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement