Guest User

Untitled

a guest
Jun 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 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. struct Vec3<S> {
  13. x: S,
  14. y: S,
  15. z: S,
  16. }
  17.  
  18. impl <S: Num> Vec3<S> {
  19. fn new(x: S, y: S, z: S) -> Vec3<S> {
  20. Vec3{
  21. x,
  22. y,
  23. z
  24. }
  25. }
  26.  
  27. fn len(&self) -> f64 {
  28. ((self.x * self.x + self.y * self.y + self.z * self.z).into()).sqrt()
  29. }
  30. }
  31.  
  32. fn main() {
  33. let test = Vec3::new(1.0, 1.0, 2.0);
  34. // println!("{}", test.len())
  35. }
Add Comment
Please, Sign In to add comment