#[non_exhaustive]pub enum Width {
Variable = 0,
U8 = 1,
U16 = 2,
U32 = 3,
U64 = 4,
}Expand description
The width of a numerical type.
§Examples
use musli::options::{self, Width, Integer};
use musli::packed::Encoding;
// Configure encoding to use variable integer encoding
const OPTIONS: musli::options::Options = options::new()
.integer(Integer::Variable)
.build();
const CONFIG: Encoding<OPTIONS> = Encoding::new().with_options();
// Variable encoding is more efficient for small numbers
let data = CONFIG.to_vec(&42u32)?;
let decoded: u32 = CONFIG.from_slice(&data)?;
assert_eq!(decoded, 42);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Variable = 0
Use a variable width encoding.
U8 = 1
8 bit width.
U16 = 2
16 bit width.
U32 = 3
32 bit width.
U64 = 4
64 bit width.
Implementations§
Source§impl Width
impl Width
Sourcepub const NATIVE: Self
pub const NATIVE: Self
The native width.
This is the width of the target platform’s native integer type.
§Examples
use musli::options::{self, Width};
use musli::packed::Encoding;
// Use native pointer width for platform-optimized encoding
const OPTIONS: musli::options::Options = options::new()
.pointer(Width::NATIVE)
.build();
const CONFIG: Encoding<OPTIONS> = Encoding::new().with_options();
// Encode a usize value using native width
let value: usize = 42;
let data = CONFIG.to_vec(&value)?;
let decoded: usize = CONFIG.from_slice(&data)?;
assert_eq!(value, decoded);Trait Implementations§
impl Copy for Width
impl Eq for Width
impl StructuralPartialEq for Width
Auto Trait Implementations§
impl Freeze for Width
impl RefUnwindSafe for Width
impl Send for Width
impl Sync for Width
impl Unpin for Width
impl UnsafeUnpin for Width
impl UnwindSafe for Width
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more