Guest User

Untitled

a guest
Jun 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. use std::ops::*;
  2.  
  3. pub trait Num:
  4. Copy
  5. + Sized
  6. + Mul<Output=Self>
  7. + Add<Output=Self>
  8. + Into<f64>
  9. {
  10. }
  11.  
  12. impl <T: Copy
  13. + Sized
  14. + Mul<Output=Self>
  15. + Add<Output=Self>
  16. + Into<f64>> Num for T {}
  17.  
  18. struct Vec3<S> {
  19. x: S,
  20. y: S,
  21. z: S,
  22. }
  23.  
  24. impl <S: Num> Vec3<S> {
  25. fn new(x: S, y: S, z: S) -> Vec3<S> {
  26. Vec3{
  27. x,
  28. y,
  29. z
  30. }
  31. }
  32.  
  33. fn len(&self) -> f64 {
  34. ((self.x * self.x + self.y * self.y + self.z * self.z).into()).sqrt()
  35. }
  36. }
  37.  
  38. fn main() {
  39. let test = Vec3::new(1.0, 1.0, 2.0);
  40. // println!("{}", test.len())
  41. }
Add Comment
Please, Sign In to add comment