1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! # The definitive vector and matrix library for Rust
//!
//! # Example
//! ```norun
//! use definitive::Vector;
//!
//! let a = Vector::from([2, 3, 1]);
//! let b = Vector::from([8, 0, 0]);
//!
//! let c = a + b;
//! ```

#![feature(const_generics, specialization)]
#![allow(incomplete_features)]
#![deny(missing_docs)]
#![cfg_attr(not(test), no_std)]

mod add;
mod add_assign;
mod clone;
mod copy;
mod debug;
mod default;
mod deref;
mod div;
mod div_assign;
mod mul;
mod mul_assign;
mod partial_eq;
mod rem;
mod rem_assign;
mod sub;
mod sub_assign;

/// A generic type representing an N dimensional vector
pub struct Vector<T = f32, const N: usize>([T; { N }]);

impl<T, const N: usize> Vector<T, { N }> {
    /// Create a new vector out of some components
    ///
    /// Note: `Vector` also implements `From<[T, {N}]>` which can be cleaner
    pub fn new(components: [T; { N }]) -> Self {
        components.into()
    }
}

impl<T, const N: usize> From<[T; { N }]> for Vector<T, { N }> {
    fn from(v: [T; { N }]) -> Self {
        Self(v)
    }
}