Guest User

Untitled

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