pub struct Vec2u(/* private fields */);Expand description
A 2-component non-owning view of an unsigned Euclidean vector.
§Guarantees
This type has the strict requirement that it can only reference a
2-component slice of u32 values. It is guaranteed to never refer to
more or less than 2 entries.
§Relation to Vector2u
Vec2u is a non-owning equivalent of Vector2u. This enables non-vector
types to either Deref or provide conversion-related utilities into
Vec2u types to be able to access and benefit from vector operations.
Implementations§
source§impl Vec2u
impl Vec2u
sourcepub const fn from_array(array: &[u32; 2]) -> &Self
pub const fn from_array(array: &[u32; 2]) -> &Self
Forms a reference to a Vec2u from a 2-component u32 array.
This function is identical to from_slice_unchecked, except it is not
marked unsafe.
§Parameters
array- an array containing 2u32values.
§Examples
Basic use:
let array: [u32; 2] = [1, 42];
let vec = Vec2u::from_array(&array);
assert_eq!(vec.as_ptr(), array.as_ptr());
assert_eq!(vec.x(), array[0]);
assert_eq!(vec.y(), array[1]);sourcepub fn from_mut_array(array: &mut [u32; 2]) -> &mut Self
pub fn from_mut_array(array: &mut [u32; 2]) -> &mut Self
Forms a mutable reference to a Vec2u from a 2-component u32 array.
This function is identical to from_mut_slice_unchecked, except it is
not marked unsafe.
§Parameters
array- an array containing 2u32values.
§Examples
Basic use:
let mut array: [u32; 2] = [1, 42];
let vec = Vec2u::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 [Vec2] from a slice of u32.
This requires that slice.len() == 2, otherwise this returns VecError.
§Parameters
slice- the slice ofu32s.
§Examples
Basic use:
let slice = &[1, 42];
let vec = Vec2u::from_slice(slice).unwrap();
assert_eq!(vec.as_ptr(), slice.as_ptr());
assert_eq!(vec.x(), slice[0]);
assert_eq!(vec.y(), slice[1]);Invalid size:
let slice = &[1];
let vec = Vec2u::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 [Vec2] from a mutable slice of u32.
This requires that slice.len() == 2, otherwise this returns VecError.
§Parameters
slice- the mutable slice ofu32s.
§Examples
Basic use:
let slice = &mut [1, 42];
let vec = Vec2u::from_mut_slice(slice).unwrap();
assert_eq!(vec.as_ptr(), slice.as_ptr());Invalid size:
let slice = &mut [1];
let vec = Vec2u::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 Vec2u
pub const unsafe fn from_ptr_unchecked<'a>(ptr: *const u32) -> &'a Vec2u
sourcepub unsafe fn from_mut_ptr_unchecked<'a>(ptr: *mut u32) -> &'a mut Vec2u
pub unsafe fn from_mut_ptr_unchecked<'a>(ptr: *mut u32) -> &'a mut Vec2u
sourcepub fn as_mut_slice(&mut self) -> &mut [u32]
pub fn as_mut_slice(&mut self) -> &mut [u32]
Returns this [Vec2] as a mutable slice of 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 2-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 2-component vector.
sourcepub fn set(&mut self, other: &Vec2u)
pub fn set(&mut self, other: &Vec2u)
Sets all the components of this vector the values from other.
§Parameters
other- the other [Vec2] to set.
Trait Implementations§
source§impl AddAssign<&Vec2u> for Vec2u
impl AddAssign<&Vec2u> for Vec2u
source§fn add_assign(&mut self, rhs: &Vec2u)
fn add_assign(&mut self, rhs: &Vec2u)
+= operation. Read moresource§impl AddAssign<&Vec2u> for Vector2u
impl AddAssign<&Vec2u> for Vector2u
source§fn add_assign(&mut self, rhs: &Vec2u)
fn add_assign(&mut self, rhs: &Vec2u)
+= operation. Read moresource§impl BorrowMut<[u32]> for Vec2u
impl BorrowMut<[u32]> for Vec2u
source§fn borrow_mut(&mut self) -> &mut [u32]
fn borrow_mut(&mut self) -> &mut [u32]
source§impl BorrowMut<Vec2u> for Vector2u
impl BorrowMut<Vec2u> for Vector2u
source§fn borrow_mut(&mut self) -> &mut Vec2u
fn borrow_mut(&mut self) -> &mut Vec2u
source§impl DivAssign<u32> for Vec2u
impl DivAssign<u32> for Vec2u
source§fn div_assign(&mut self, rhs: u32)
fn div_assign(&mut self, rhs: u32)
/= operation. Read moresource§impl MulAssign<u32> for Vec2u
impl MulAssign<u32> for Vec2u
source§fn mul_assign(&mut self, rhs: u32)
fn mul_assign(&mut self, rhs: u32)
*= operation. Read moresource§impl PartialOrd for Vec2u
impl PartialOrd for Vec2u
source§impl RemAssign<u32> for Vec2u
impl RemAssign<u32> for Vec2u
source§fn rem_assign(&mut self, rhs: u32)
fn rem_assign(&mut self, rhs: u32)
%= operation. Read moresource§impl SubAssign<&Vec2u> for Vec2u
impl SubAssign<&Vec2u> for Vec2u
source§fn sub_assign(&mut self, rhs: &Vec2u)
fn sub_assign(&mut self, rhs: &Vec2u)
-= operation. Read moresource§impl SubAssign<&Vec2u> for Vector2u
impl SubAssign<&Vec2u> for Vector2u
source§fn sub_assign(&mut self, rhs: &Vec2u)
fn sub_assign(&mut self, rhs: &Vec2u)
-= operation. Read more