daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mod identities
  2. {
  3.     use std::ops::{Add};
  4.  
  5.     pub trait AdditiveIdentity<_AdditiveIdentity = Self> where
  6.         Self: Sized + Add<_AdditiveIdentity, Output = Self>,
  7.         _AdditiveIdentity: Sized + Add<Self, Output = Self>
  8.     {
  9.         const ADDITIVE_IDENTITY: _AdditiveIdentity;
  10.     }
  11.    
  12.     impl AdditiveIdentity for i32
  13.     {
  14.         const ADDITIVE_IDENTITY: Self = 0;
  15.     }
  16.    
  17.     impl AdditiveIdentity for f64
  18.     {
  19.         const ADDITIVE_IDENTITY: Self = 0.0;
  20.     }
  21. }
  22.  
  23. mod vector
  24. {
  25.     use crate::identities::{AdditiveIdentity};
  26.    
  27.     pub struct Vector<T>
  28.     {
  29.         pub components: T
  30.     }
  31.    
  32.     impl<T> Vector<T> where T: AdditiveIdentity {
  33.        pub const ZERO_VECTOR: Vector<[T; 3]> = Vector{components: [ T::ADDITIVE_IDENTITY,  T::ADDITIVE_IDENTITY,  T::ADDITIVE_IDENTITY]};
  34.     }
  35. }
  36.  
  37. fn main() {
  38.     println!("Hello, world!");
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top