[][src]Struct vectrs::Vector

pub struct Vector<T, const N: usize> { /* fields omitted */ }

Represents a constant-size, n-dimensional vector.

Examples

Accessors are provided for small vectors.

let vector = Vector::from((1, 2, 3, 4));
assert_eq!(vector.x(), 1);
assert_eq!(vector.y(), 2);
assert_eq!(vector.z(), 3);

Data is represented internally using an array. Vector<T, N> implements Deref<Target = [T]> so all slice methods are available.

let vector: Vector<u8, 4> = Default::default();
// this uses the `[T]::len()` implementation.
assert_eq!(vector.len(), 4);

Implementations

impl<T: Copy, const N: usize> Vector<T, N> where
    Self: X, 
[src]

pub fn x(&self) -> T[src]

Returns this component of the vector.

pub fn x_ref(&self) -> &T[src]

Returns a reference to this component of the vector.

pub fn x_mut(&mut self) -> &mut T[src]

Returns a mutable reference to this component of the vector.

impl<T: Copy, const N: usize> Vector<T, N> where
    Self: Y, 
[src]

pub fn y(&self) -> T[src]

Returns this component of the vector.

pub fn y_ref(&self) -> &T[src]

Returns a reference to this component of the vector.

pub fn y_mut(&mut self) -> &mut T[src]

Returns a mutable reference to this component of the vector.

impl<T: Copy, const N: usize> Vector<T, N> where
    Self: Z, 
[src]

pub fn z(&self) -> T[src]

Returns this component of the vector.

pub fn z_ref(&self) -> &T[src]

Returns a reference to this component of the vector.

pub fn z_mut(&mut self) -> &mut T[src]

Returns a mutable reference to this component of the vector.

impl<T: Copy, const N: usize> Vector<T, N> where
    Self: W, 
[src]

pub fn w(&self) -> T[src]

Returns this component of the vector.

pub fn w_ref(&self) -> &T[src]

Returns a reference to this component of the vector.

pub fn w_mut(&mut self) -> &mut T[src]

Returns a mutable reference to this component of the vector.

impl<T: Copy + Zero, const N: usize> Vector<T, N>[src]

pub fn zero() -> Self[src]

Returns a zero vector.

impl<T, const N: usize> Vector<T, N>[src]

pub fn as_slice(&self) -> &[T][src]

Views the underlying vector representation as a slice.

pub fn as_mut_slice(&mut self) -> &mut [T][src]

Views the underlying vector representation as a mutable slice.

impl<T, const N: usize> Vector<T, N> where
    T: Copy + Mul<Output = T> + Sum<T>, 
[src]

pub fn dot(&self, other: &Self) -> T[src]

Calculates the dot-product between self and other.

impl<T, const N: usize> Vector<T, N> where
    T: Copy + Abs, 
[src]

pub fn abs(self) -> Self[src]

Returns the absolute value of the vector.

impl<T, const N: usize> Vector<T, N> where
    T: Copy + Sum<T> + Abs, 
[src]

pub fn l1_norm(&self) -> T[src]

Returns the L1 norm of the vector.

Also known as Manhattan Distance or Taxicab norm. L1 Norm is the sum of the magnitudes of the vectors in a space.

Trait Implementations

impl<T, const N: usize, '_> Add<&'_ Vector<T, N>> for Vector<T, N> where
    T: Copy + Zero + Add<Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the + operator.

impl<T, const N: usize, '_, '_> Add<&'_ Vector<T, N>> for &'_ Vector<T, N> where
    T: Copy + Zero + Add<Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the + operator.

impl<T, const N: usize> Add<Vector<T, N>> for Vector<T, N> where
    T: Copy + Zero + Add<Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the + operator.

impl<T, const N: usize, '_> AddAssign<&'_ Vector<T, N>> for Vector<T, N> where
    T: Copy + AddAssign
[src]

impl<T, const N: usize> AddAssign<Vector<T, N>> for Vector<T, N> where
    T: Copy + AddAssign
[src]

impl<T: Clone, const N: usize> Clone for Vector<T, N>[src]

impl<T: Copy, const N: usize> Copy for Vector<T, N>[src]

impl<T: Debug, const N: usize> Debug for Vector<T, N>[src]

impl<T, const N: usize> Default for Vector<T, N> where
    T: Copy + Zero, 
[src]

impl<T, const N: usize> Deref for Vector<T, N>[src]

type Target = [T]

The resulting type after dereferencing.

impl<T, const N: usize> DerefMut for Vector<T, N>[src]

impl<T: Eq, const N: usize> Eq for Vector<T, N>[src]

impl<T, const N: usize> From<[T; N]> for Vector<T, N>[src]

impl<T> From<(T, T, T, T)> for Vector<T, 4>[src]

impl<T> From<(T, T, T)> for Vector<T, 3>[src]

impl<T> From<(T, T)> for Vector<T, 2>[src]

impl<T: Hash, const N: usize> Hash for Vector<T, N>[src]

impl<T: Copy, const N: usize> IntoIterator for Vector<T, N>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T, N>

Which kind of iterator are we turning this into?

impl<'a, T, const N: usize> Mul<&'a T> for Vector<T, N> where
    T: Copy + Zero + Mul<&'a T, Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the * operator.

impl<'a, T, const N: usize, '_> Mul<&'a T> for &'_ Vector<T, N> where
    T: Copy + Zero + Mul<&'a T, Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the * operator.

impl<'a, T, const N: usize> Mul<T> for Vector<T, N> where
    T: Copy + Zero + Mul<T, Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the * operator.

impl<'a, T, const N: usize, '_> Mul<T> for &'_ Vector<T, N> where
    T: Copy + Zero + Mul<T, Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the * operator.

impl<T: Ord, const N: usize> Ord for Vector<T, N>[src]

impl<T: PartialEq, const N: usize> PartialEq<Vector<T, N>> for Vector<T, N>[src]

impl<T: PartialOrd, const N: usize> PartialOrd<Vector<T, N>> for Vector<T, N>[src]

impl<T, const N: usize> StructuralEq for Vector<T, N>[src]

impl<T, const N: usize> StructuralPartialEq for Vector<T, N>[src]

impl<T, const N: usize, '_> Sub<&'_ Vector<T, N>> for Vector<T, N> where
    T: Copy + Zero + Sub<Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the - operator.

impl<T, const N: usize, '_, '_> Sub<&'_ Vector<T, N>> for &'_ Vector<T, N> where
    T: Copy + Zero + Sub<Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the - operator.

impl<T, const N: usize> Sub<Vector<T, N>> for Vector<T, N> where
    T: Copy + Zero + Sub<Output = T>, 
[src]

type Output = Vector<T, N>

The resulting type after applying the - operator.

impl<T, const N: usize, '_> SubAssign<&'_ Vector<T, N>> for Vector<T, N> where
    T: Copy + SubAssign
[src]

impl<T, const N: usize> SubAssign<Vector<T, N>> for Vector<T, N> where
    T: Copy + SubAssign
[src]

Auto Trait Implementations

impl<T, const N: usize> RefUnwindSafe for Vector<T, N> where
    T: RefUnwindSafe
[src]

impl<T, const N: usize> Send for Vector<T, N> where
    T: Send
[src]

impl<T, const N: usize> Sync for Vector<T, N> where
    T: Sync
[src]

impl<T, const N: usize> Unpin for Vector<T, N> where
    T: Unpin
[src]

impl<T, const N: usize> UnwindSafe for Vector<T, N> where
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.