pub struct Vec4u(/* private fields */);Expand description
A 4-component non-owning view of an unsigned Euclidean vector.
§Guarantees
This type has the strict requirement that it can only reference a
4-component slice of u32 values. It is guaranteed to never refer to
more or less than 4 entries.
§Relation to Vector4u
Vec4u is a non-owning equivalent of Vector4u. This enables non-vector
types to either Deref or provide conversion-related utilities into
Vec4u types to be able to access and benefit from vector operations.
Implementations§
source§impl Vec4u
impl Vec4u
sourcepub const fn from_array(array: &[u32; 4]) -> &Self
pub const fn from_array(array: &[u32; 4]) -> &Self
Forms a reference to a Vec4u from a 4-component u32 array.
This function is identical to from_slice_unchecked, except it is not
marked unsafe.
§Parameters
array- an array containing 4u32values.
§Examples
Basic use:
let array: [u32; 4] = [1, 42, 314, 9];
let vec = Vec4u::from_array(&array);
assert_eq!(vec.as_ptr(), array.as_ptr());
assert_eq!(vec.x(), array[0]);
assert_eq!(vec.y(), array[1]);
assert_eq!(vec.z(), array[2]);
assert_eq!(vec.w(), array[3]);sourcepub fn from_mut_array(array: &mut [u32; 4]) -> &mut Self
pub fn from_mut_array(array: &mut [u32; 4]) -> &mut Self
Forms a mutable reference to a Vec4u from a 4-component u32 array.
This function is identical to from_mut_slice_unchecked, except it is
not marked unsafe.
§Parameters
array- an array containing 4u32values.
§Examples
Basic use:
let mut array: [u32; 4] = [1, 420, 314, 9];
let vec = Vec4u::from_mut_array(&mut array);
assert_eq!(vec.as_ptr(), array.as_ptr());sourcepub const fn from_slice(slice: &[u32]) -> Result<&Self, VecError>
pub const fn from_slice(slice: &[u32]) -> Result<&Self, VecError>
Forms a reference to a Vec4u from a slice of u32.
This requires that slice.len() == 4, otherwise this returns VecError.
§Parameters
slice- the slice ofu32s.
§Examples
Basic use:
let slice = &[1, 42, 314, 9];
let vec = Vec4u::from_slice(slice).unwrap();
assert_eq!(vec.as_ptr(), slice.as_ptr());
assert_eq!(vec.x(), slice[0]);
assert_eq!(vec.y(), slice[1]);
assert_eq!(vec.z(), slice[2]);
assert_eq!(vec.w(), slice[3]);Invalid size:
let slice = &[1];
let vec = Vec4u::from_slice(slice);
assert!(vec.is_err());sourcepub fn from_mut_slice(slice: &mut [u32]) -> Result<&mut Self, VecError>
pub fn from_mut_slice(slice: &mut [u32]) -> Result<&mut Self, VecError>
Forms a mutable reference to a Vec4u from a mutable slice of u32.
This requires that slice.len() == 4, otherwise this returns VecError.
§Parameters
slice- the mutable slice ofu32s.
§Examples
Basic use:
let slice = &mut [1, 42, 314, 9];
let vec = Vec4u::from_mut_slice(slice).unwrap();
assert_eq!(vec.as_ptr(), slice.as_ptr());Invalid size:
let slice = &mut [1];
let vec = Vec4u::from_mut_slice(slice);
assert!(vec.is_err());sourcepub const unsafe fn from_slice_unchecked(slice: &[u32]) -> &Self
pub const unsafe fn from_slice_unchecked(slice: &[u32]) -> &Self
sourcepub unsafe fn from_mut_slice_unchecked(slice: &mut [u32]) -> &mut Self
pub unsafe fn from_mut_slice_unchecked(slice: &mut [u32]) -> &mut Self
sourcepub const unsafe fn from_ptr_unchecked<'a>(ptr: *const u32) -> &'a Vec4u
pub const unsafe fn from_ptr_unchecked<'a>(ptr: *const u32) -> &'a Vec4u
sourcepub unsafe fn from_mut_ptr_unchecked<'a>(ptr: *mut u32) -> &'a mut Vec4u
pub unsafe fn from_mut_ptr_unchecked<'a>(ptr: *mut u32) -> &'a mut Vec4u
sourcepub fn as_mut_slice(&mut self) -> &mut [u32]
pub fn as_mut_slice(&mut self) -> &mut [u32]
sourcepub fn as_mut_ptr(&mut self) -> *mut u32
pub fn as_mut_ptr(&mut self) -> *mut u32
Returns a mutable raw pointer to u32 of the vector’s buffer.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut u32>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut u32>
Returns a mutable iterator over the vector.
sourcepub fn x_mut(&mut self) -> &mut u32
pub fn x_mut(&mut self) -> &mut u32
Returns a mutable reference to the X-coordinate of this 3-component vector.
sourcepub fn y_mut(&mut self) -> &mut u32
pub fn y_mut(&mut self) -> &mut u32
Returns a mutable reference to the Y-coordinate of this 3-component vector.
sourcepub fn z_mut(&mut self) -> &mut u32
pub fn z_mut(&mut self) -> &mut u32
Returns a mutable reference to the Z-coordinate of this 3-component vector.
sourcepub fn w_mut(&mut self) -> &mut u32
pub fn w_mut(&mut self) -> &mut u32
Returns a mutable reference to the W-coordinate of this 3-component vector.
sourcepub fn xy_mut(&mut self) -> &mut Vec2u
pub fn xy_mut(&mut self) -> &mut Vec2u
Returns a mutable reference to the xy coordinates of this vector.
sourcepub fn yz_mut(&mut self) -> &mut Vec2u
pub fn yz_mut(&mut self) -> &mut Vec2u
Returns a mutable reference to the yz coordinates of this vector.
sourcepub fn zw_mut(&mut self) -> &mut Vec2u
pub fn zw_mut(&mut self) -> &mut Vec2u
Returns a mutable reference to the zw coordinates of this vector.
sourcepub fn xyz_mut(&mut self) -> &mut Vec3u
pub fn xyz_mut(&mut self) -> &mut Vec3u
Returns a mutable reference to the yz coordinates of this vector.
sourcepub fn yzw_mut(&mut self) -> &mut Vec3u
pub fn yzw_mut(&mut self) -> &mut Vec3u
Returns a mutable reference to the zw coordinates of this vector.
Trait Implementations§
source§impl AddAssign<&Vec4u> for Vec4u
impl AddAssign<&Vec4u> for Vec4u
source§fn add_assign(&mut self, rhs: &Vec4u)
fn add_assign(&mut self, rhs: &Vec4u)
+= operation. Read moresource§impl AddAssign<&Vec4u> for Vector4u
impl AddAssign<&Vec4u> for Vector4u
source§fn add_assign(&mut self, rhs: &Vec4u)
fn add_assign(&mut self, rhs: &Vec4u)
+= operation. Read moresource§impl BorrowMut<[u32]> for Vec4u
impl BorrowMut<[u32]> for Vec4u
source§fn borrow_mut(&mut self) -> &mut [u32]
fn borrow_mut(&mut self) -> &mut [u32]
source§impl BorrowMut<Vec4u> for Vector4u
impl BorrowMut<Vec4u> for Vector4u
source§fn borrow_mut(&mut self) -> &mut Vec4u
fn borrow_mut(&mut self) -> &mut Vec4u
source§impl DivAssign<u32> for Vec4u
impl DivAssign<u32> for Vec4u
source§fn div_assign(&mut self, rhs: u32)
fn div_assign(&mut self, rhs: u32)
/= operation. Read moresource§impl MulAssign<u32> for Vec4u
impl MulAssign<u32> for Vec4u
source§fn mul_assign(&mut self, rhs: u32)
fn mul_assign(&mut self, rhs: u32)
*= operation. Read moresource§impl PartialOrd for Vec4u
impl PartialOrd for Vec4u
source§impl RemAssign<u32> for Vec4u
impl RemAssign<u32> for Vec4u
source§fn rem_assign(&mut self, rhs: u32)
fn rem_assign(&mut self, rhs: u32)
%= operation. Read moresource§impl SubAssign<&Vec4u> for Vec4u
impl SubAssign<&Vec4u> for Vec4u
source§fn sub_assign(&mut self, rhs: &Vec4u)
fn sub_assign(&mut self, rhs: &Vec4u)
-= operation. Read moresource§impl SubAssign<&Vec4u> for Vector4u
impl SubAssign<&Vec4u> for Vector4u
source§fn sub_assign(&mut self, rhs: &Vec4u)
fn sub_assign(&mut self, rhs: &Vec4u)
-= operation. Read more