Struct vec_x::VecX

source ·
pub struct VecX<T, const N: usize> {
    pub data: [T; N],
}
Expand description

A structure representing a fixed-length array of arbitrary elements and arbitrary length. Since it was created primarily to represent mathematical vectors and colors, it supports four arithmetic operations.

任意の要素、任意の長さの固定長配列を表す構造体です。 主に数学的なベクトルや色を表すために作成したため、四則演算をサポートしています。

use vec_x::{VecX};

let vec1 = VecX::new([1, 2, 3]);
let vec2 = VecX::new([4, 5, 6]);

// Add
assert_eq!(vec1 + vec2, VecX::new([5, 7, 9]));
// Sub
assert_eq!(vec1 - vec2, VecX::new([-3, -3, -3]));
// Mul
assert_eq!(vec1 * vec2, VecX::new([4, 10, 18]));
// Div
assert_eq!(vec1 / vec2, VecX::new([0, 0, 0]));
// Rem
assert_eq!(vec1 % vec2, VecX::new([1, 2, 3]));

// AddAssign
let mut vec = VecX::new([1, 2, 3]);
vec += VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([5, 7, 9]));
// SubAssign
let mut vec = VecX::new([1, 2, 3]);
vec -= VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([-3, -3, -3]));
// MulAssign
let mut vec = VecX::new([1, 2, 3]);
vec *= VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([4, 10, 18]));
// DivAssign
let mut vec = VecX::new([1, 2, 3]);
vec /= VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([0, 0, 0]));
// RemAssign
let mut vec = VecX::new([1, 2, 3]);
vec %= VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([1, 2, 3]));

Non-numeric elements can also be array elements.

数値以外を配列要素にすることもできます。

use vec_x::{VecX};

let vec1 = VecX::new(["a", "b", "c"]);
use vec_x::{VecX};


let vec1 = VecX::new(["a", "b", "c"]);
let vec2 = VecX::new(["d", "e", "f"]);

vec1 + vec2; // compile error!

Using type aliases, as shown below, improves code readability.

以下のように型エイリアスを使用することで、コードの可読性が向上します。

use vec_x::{VecX};

type XYZ = VecX<f64, 3>;
type RGBA = VecX<u8, 4>;

struct Point {
   position: XYZ,
   color: RGBA,
}

let point = Point {
   position: XYZ::new([1.0, 2.0, 3.0]),
   color: RGBA::new([255, 0, 0, 255]),
};

Fields§

§data: [T; N]

Implementations§

source§

impl<T, const N: usize> VecX<T, N>

source

pub fn new(data: [T; N]) -> Self

Generate a new VecX.

新しい VecX を生成する。

§Examples
use vec_x::{VecX};

let vec = VecX::new([1, 2, 3]);
source

pub fn new_with(value: T) -> Self
where T: Copy,

Generate a VecX initialized with a single value.

単一の値で初期化された VecX を生成する。

§Examples
use vec_x::{VecX};

let vec = VecX::new_with(1);

assert_eq!(vec, VecX::new([1, 1, 1]));

Trait Implementations§

source§

impl<T: Num + Copy, const N: usize> Add for VecX<T, N>

§

type Output = VecX<T, N>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Num + AddAssign, const N: usize> AddAssign for VecX<T, N>

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl<T: Clone, const N: usize> Clone for VecX<T, N>

source§

fn clone(&self) -> VecX<T, N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug, const N: usize> Debug for VecX<T, N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default + Copy, const N: usize> Default for VecX<T, N>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T: Num + Copy, const N: usize> Div for VecX<T, N>

§

type Output = VecX<T, N>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
source§

impl<T: Num + DivAssign, const N: usize> DivAssign for VecX<T, N>

source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
source§

impl<T: Hash, const N: usize> Hash for VecX<T, N>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T, const N: usize> Index<usize> for VecX<T, N>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> IndexMut<usize> for VecX<T, N>

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<T: Num + Copy, const N: usize> Mul for VecX<T, N>

§

type Output = VecX<T, N>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl<T: Num + MulAssign, const N: usize> MulAssign for VecX<T, N>

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl<T: PartialEq, const N: usize> PartialEq for VecX<T, N>

source§

fn eq(&self, other: &VecX<T, N>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Num + Copy, const N: usize> Rem for VecX<T, N>

§

type Output = VecX<T, N>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
source§

impl<T: Num + RemAssign, const N: usize> RemAssign for VecX<T, N>

source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
source§

impl<T: Num + Copy, const N: usize> Sub for VecX<T, N>

§

type Output = VecX<T, N>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl<T: Num + SubAssign, const N: usize> SubAssign for VecX<T, N>

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl<T: Copy, const N: usize> Copy for VecX<T, N>

source§

impl<T: Eq, const N: usize> Eq for VecX<T, N>

source§

impl<T, const N: usize> StructuralPartialEq for VecX<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for VecX<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for VecX<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for VecX<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for VecX<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for VecX<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for VecX<T, N>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,