Guest User

Untitled

a guest
Dec 15th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  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> {
  33. pub /*const*/ fn additive_identity<U>() -> Vector<[U; 3]> where U: AdditiveIdentity
  34. {
  35. const ZERO_VECTOR: Vector<[U; 3]> = Vector{components: [ U::ADDITIVE_IDENTITY, U::ADDITIVE_IDENTITY, U::ADDITIVE_IDENTITY]};
  36. ZERO_VECTOR
  37.  
  38. // let f1 = || { Vector{components: [ U::ADDITIVE_IDENTITY, U::ADDITIVE_IDENTITY, U::ADDITIVE_IDENTITY]} };
  39. // let f2 = || { const ZERO_VECTOR: Vector<[U; 3]> = f1(); ZERO_VECTOR };
  40. // f2()
  41. }
  42. }
  43. }
  44.  
  45. fn main() {
  46. println!("Hello, world!");
  47. }
Add Comment
Please, Sign In to add comment