Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::ops::*;
- pub trait Num:
- Copy
- + Sized
- + Mul<Output=Self>
- + Add<Output=Self>
- + Into<f64>
- {
- }
- impl <T: Copy
- + Sized
- + Mul<Output=Self>
- + Add<Output=Self>
- + Into<f64>> Num for T {}
- struct Vec3<S> {
- x: S,
- y: S,
- z: S,
- }
- impl <S: Num> Vec3<S> {
- fn new(x: S, y: S, z: S) -> Vec3<S> {
- Vec3{
- x,
- y,
- z
- }
- }
- fn len(&self) -> f64 {
- ((self.x * self.x + self.y * self.y + self.z * self.z).into()).sqrt()
- }
- }
- fn main() {
- let test = Vec3::new(1.0, 1.0, 2.0);
- // println!("{}", test.len())
- }
Add Comment
Please, Sign In to add comment