FlagVec

Struct FlagVec 

Source
pub struct FlagVec<N: FlagLength, I = usize>(/* private fields */);
Expand description

A data structure an indexed collection of N bit bit-flag like objects Behaves like DefaultVec<u32> but only considers the last N bits

Use StaticFlagVec when N is known at compile time, or DynamicFlagVec if it isn’t

Implementations§

Source§

impl FlagVec<u32>

Source

pub fn new(flag_bit_len: u32) -> Self

Source§

impl<N: FlagLength, I: Into<usize>> FlagVec<N, I>

Source

pub fn or_assign(&mut self, x: I, v: u32)

Equivalent to self.set(x, self.get(x) | v)

use default_vec2::StaticFlagVec;
let mut s: StaticFlagVec<4> = StaticFlagVec::default();
s.or_assign(0, 3);
assert_eq!(s.get(0), 3);
s.or_assign(0, 9);
assert_eq!(s.get(0), 11);
Source

pub fn and_assign(&mut self, x: I, v: u32)

Equivalent to self.set(x, self.get(x) & v)

use default_vec2::StaticFlagVec;
let mut s: StaticFlagVec<4> = StaticFlagVec::default();
s.or_assign(0, 11);
s.and_assign(0, 5);
assert_eq!(s.get(0), 1);
Source

pub fn set(&mut self, x: I, v: u32)

Sets the element and index x to the last N bits of v

use default_vec2::StaticFlagVec;
let mut s: StaticFlagVec<4> = StaticFlagVec::default();
s.set(0, 3);
assert_eq!(s.get(0), 3);
s.set(0, 9);
assert_eq!(s.get(0), 9);
s.set(0, 18);
assert_eq!(s.get(0), 2);
Source

pub fn get(&self, x: I) -> u32

Returns the element and index x

Source

pub fn get_reserve(&mut self, x: I) -> u32

Same as get but already reserves space for x

Source

pub fn clear(&mut self)

Removes all elements from the set

Source

pub fn capacity(&self) -> usize

Source

pub fn iter(&self) -> impl Iterator<Item = u32> + '_

Iterate over the elements of self

use default_vec2::StaticFlagVec;
let mut s: StaticFlagVec<10> = StaticFlagVec::default();
s.set(0, 42);
s.set(2, 999);
s.set(3, 365);
let res: Vec<_> = s.iter().collect();
assert_eq!(&res[..4], [42, 0, 999, 365])

Trait Implementations§

Source§

impl<N: FlagLength, I> Clone for FlagVec<N, I>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

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

Performs copy-assignment from source. Read more
Source§

impl<N: FlagLength, I: Into<usize>> Debug for FlagVec<N, I>

Source§

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

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

impl<N: FlagLength, I> PartialEq for FlagVec<N, I>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<N: FlagLength, I> Eq for FlagVec<N, I>

Auto Trait Implementations§

§

impl<N, I> Freeze for FlagVec<N, I>
where N: Freeze,

§

impl<N, I> RefUnwindSafe for FlagVec<N, I>

§

impl<N, I> Send for FlagVec<N, I>
where N: Send, I: Send,

§

impl<N, I> Sync for FlagVec<N, I>
where N: Sync, I: Sync,

§

impl<N, I> Unpin for FlagVec<N, I>
where N: Unpin, I: Unpin,

§

impl<N, I> UnwindSafe for FlagVec<N, I>
where N: UnwindSafe, I: 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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,

Source§

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>,

Source§

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>,

Source§

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.