Struct vach::archive::Flags

source ·
pub struct Flags { /* private fields */ }
Available on crate feature archive only.
Expand description

Abstracted flag access and manipulation struct. A knock-off minimal bitflags of sorts.

Implementations§

source§

impl Flags

source

pub const RESERVED_MASK: u32 = 4_294_901_760u32

The flags used within the crate, to whom all access is denied. Any interaction with Flags::set() will yield an error.

source

pub const SIZE: usize = 4usize

The size in bytes of any flags entry

source

pub const COMPRESSED_FLAG: u32 = 2_147_483_648u32

This flag shows that the adjacent entry is compressed

source

pub const LZ4_COMPRESSED: u32 = 1_073_741_824u32

This entry was compressed using the LZ4 scheme for very fast decompression with average compression ratios

source

pub const SNAPPY_COMPRESSED: u32 = 536_870_912u32

This entry was compressed using the snappy scheme for balanced compression properties

source

pub const BROTLI_COMPRESSED: u32 = 268_435_456u32

This entry was compressed using the brotli scheme for higher compression ratios but much (depends on the quality of compression) slower compression speed

source

pub const SIGNED_FLAG: u32 = 134_217_728u32

The flag that denotes that the archive source has signatures

source

pub const ENCRYPTED_FLAG: u32 = 33_554_432u32

The flag that shows data in the leaf in encrypted

source

pub fn from_bits(bits: u32) -> Self

Construct a Flags struct from a u32 number

source

pub fn bits(&self) -> u32

Returns a copy of the underlying number.

source

pub fn empty() -> Self

Yield a new empty Flags instance.

use vach::prelude::Flags;
let flag = Flags::from_bits(0b0000_0000_0000_0000);
assert_eq!(Flags::empty(), flag);
source

pub fn set(&mut self, bit: u32, toggle: bool) -> InternalResult<u32>

Returns a error if mask contains a reserved bit. Set a flag into the underlying structure. The toggle parameter specifies whether to insert the flags (when true), or to pop the flag, (when false).

As the Flags struct uses u32 under the hood, one can (in practice) set as many as 32 different bits, but some are reserved for internal use (ie the first 16 bits). However one can use the remaining 16 bits just fine, as seen in the example. Just using the 0b0000_0000_0000_0000 literal works because most platforms are little endian. On big-endian platforms, like ARM (raspberry PI and Apple Silicon), use the full u32 literal (0b0000_0000_0000_0000_0000_0000_0000_0000), since the shorthand literal actually places bytes in the restricted range of bits.

use vach::prelude::Flags;

let mut flag = Flags::from_bits(0b0000_0000_0000_0000);
flag.set(0b0000_1000_0000_0000, true).unwrap();
flag.set(0b1000_0000_0000_0000, true).unwrap();

assert_eq!(flag.bits(), 0b1000_1000_0000_0000);
assert!(flag.contains(0b1000_0000_0000_0000));

// --------------------------v---------
flag.set(0b0000_1000_0000_0001, false).unwrap(); // 0 flags remain zero
assert_eq!(flag.bits(), 0b1000_0000_0000_0000);
Errors
  • Trying to set a bit in the forbidden section of the flags
source

pub fn contains(&self, bit: u32) -> bool

Checks whether the given flag is set.

use vach::prelude::Flags;

let mut flag = Flags::from_bits(0b0000_0000_0000_0000);

flag.set(0b1000_0000_0000_0000, true).unwrap();
assert!(flag.contains(0b1000_0000_0000_0000));

Trait Implementations§

source§

impl Clone for Flags

source§

fn clone(&self) -> Flags

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 Debug for Flags

source§

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

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

impl Default for Flags

source§

fn default() -> Flags

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

impl Display for Flags

source§

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

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

impl PartialEq for Flags

source§

fn eq(&self, other: &Flags) -> 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 Copy for Flags

source§

impl StructuralPartialEq for Flags

Auto Trait Implementations§

§

impl RefUnwindSafe for Flags

§

impl Send for Flags

§

impl Sync for Flags

§

impl Unpin for Flags

§

impl UnwindSafe for Flags

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V