pub struct Flags { /* private fields */ }
Expand description
Abstracted flag access and manipulation struct
.
A knock-off minimal bitflags of sorts.
Implementations§
source§impl Flags
impl Flags
sourcepub const RESERVED_MASK: u32 = 4_294_901_760u32
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.
sourcepub const COMPRESSED_FLAG: u32 = 2_147_483_648u32
pub const COMPRESSED_FLAG: u32 = 2_147_483_648u32
This flag shows that the adjacent entry is compressed
sourcepub const LZ4_COMPRESSED: u32 = 1_073_741_824u32
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
sourcepub const SNAPPY_COMPRESSED: u32 = 536_870_912u32
pub const SNAPPY_COMPRESSED: u32 = 536_870_912u32
This entry was compressed using the snappy scheme for balanced compression properties
sourcepub const BROTLI_COMPRESSED: u32 = 268_435_456u32
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
sourcepub const SIGNED_FLAG: u32 = 134_217_728u32
pub const SIGNED_FLAG: u32 = 134_217_728u32
The flag that denotes that the archive source has signatures
sourcepub const ENCRYPTED_FLAG: u32 = 33_554_432u32
pub const ENCRYPTED_FLAG: u32 = 33_554_432u32
The flag that shows data in the leaf in encrypted
sourcepub fn empty() -> Self
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);
sourcepub fn set(&mut self, bit: u32, toggle: bool) -> InternalResult<u32>
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