Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mod identities
- {
- use std::ops::{Add};
- pub trait AdditiveIdentity<_AdditiveIdentity = Self> where
- Self: Sized + Add<_AdditiveIdentity, Output = Self>,
- _AdditiveIdentity: Sized + Add<Self, Output = Self>
- {
- const ADDITIVE_IDENTITY: _AdditiveIdentity;
- }
- impl AdditiveIdentity for i32
- {
- const ADDITIVE_IDENTITY: Self = 0;
- }
- impl AdditiveIdentity for f64
- {
- const ADDITIVE_IDENTITY: Self = 0.0;
- }
- }
- mod vector
- {
- use crate::identities::{AdditiveIdentity};
- pub struct Vector<T>
- {
- pub components: T
- }
- impl<T> Vector<T> where T: AdditiveIdentity {
- pub const ZERO_VECTOR: Vector<[T; 3]> = Vector{components: [ T::ADDITIVE_IDENTITY, T::ADDITIVE_IDENTITY, T::ADDITIVE_IDENTITY]};
- }
- }
- fn main() {
- println!("Hello, world!");
- }
Add Comment
Please, Sign In to add comment