pub struct Dodecet { /* private fields */ }Expand description
A 12-bit dodecet value (0-4095)
§Example
use dodecet_encoder::Dodecet;
let d = Dodecet::from_hex(0xABC);
assert_eq!(d.value(), 0xABC);
assert_eq!(d.nibble(0).unwrap(), 0xC);
assert_eq!(d.nibble(1).unwrap(), 0xB);
assert_eq!(d.nibble(2).unwrap(), 0xA);Implementations§
Source§impl Dodecet
impl Dodecet
Sourcepub unsafe fn from_hex_unchecked(value: u16) -> Self
pub unsafe fn from_hex_unchecked(value: u16) -> Self
Sourcepub const fn from_hex(value: u16) -> Self
pub const fn from_hex(value: u16) -> Self
Create a dodecet from a hex value
§Example
use dodecet_encoder::Dodecet;
let d = Dodecet::from_hex(0xABC);
assert_eq!(d.value(), 0xABC);Sourcepub fn from_signed(value: i16) -> Self
pub fn from_signed(value: i16) -> Self
Create a dodecet from a signed i16 value (-2048 to 2047)
§Example
use dodecet_encoder::Dodecet;
let d = Dodecet::from_signed(-100);
assert_eq!(d.as_signed(), -100);Sourcepub fn value(self) -> u16
pub fn value(self) -> u16
Get the raw value
§Example
use dodecet_encoder::Dodecet;
let d = Dodecet::from_hex(0xABC);
assert_eq!(d.value(), 0xABC);Sourcepub fn is_zero(self) -> bool
pub fn is_zero(self) -> bool
Check if dodecet is zero
§Example
use dodecet_encoder::Dodecet;
assert!(Dodecet::from_hex(0).is_zero());
assert!(!Dodecet::from_hex(0xABC).is_zero());Sourcepub fn is_max(self) -> bool
pub fn is_max(self) -> bool
Check if dodecet is at maximum value
§Example
use dodecet_encoder::Dodecet;
assert!(Dodecet::from_hex(0xFFF).is_max());
assert!(!Dodecet::from_hex(0xABC).is_max());Sourcepub fn count_ones(self) -> u32
pub fn count_ones(self) -> u32
Count set bits (population count)
§Example
use dodecet_encoder::Dodecet;
let d = Dodecet::from_hex(0xFFF); // All bits set
assert_eq!(d.count_ones(), 12);Sourcepub fn count_zeros(self) -> u32
pub fn count_zeros(self) -> u32
Count unset bits
§Example
use dodecet_encoder::Dodecet;
let d = Dodecet::from_hex(0x000); // No bits set
// Note: count_zeros() operates on underlying u16, returns 16 for 0x000Sourcepub fn wrapping_add(self, other: Dodecet) -> Dodecet
pub fn wrapping_add(self, other: Dodecet) -> Dodecet
Arithmetic addition with wrapping
Sourcepub fn wrapping_sub(self, other: Dodecet) -> Dodecet
pub fn wrapping_sub(self, other: Dodecet) -> Dodecet
Arithmetic subtraction with wrapping
Sourcepub fn wrapping_mul(self, other: Dodecet) -> Dodecet
pub fn wrapping_mul(self, other: Dodecet) -> Dodecet
Arithmetic multiplication with wrapping
Sourcepub fn to_hex_string(self) -> String
pub fn to_hex_string(self) -> String
Convert to hex string (3 characters)
§Example
use dodecet_encoder::Dodecet;
let d = Dodecet::from_hex(0xABC);
assert_eq!(d.to_hex_string(), "ABC");Sourcepub fn from_hex_str(s: &str) -> Result<Self>
pub fn from_hex_str(s: &str) -> Result<Self>
Parse from hex string
§Example
use dodecet_encoder::Dodecet;
let d = Dodecet::from_hex_str("ABC").unwrap();
assert_eq!(d.value(), 0xABC);Sourcepub fn to_binary_string(self) -> String
pub fn to_binary_string(self) -> String
Convert to binary string (12 characters)
§Example
use dodecet_encoder::Dodecet;
let d = Dodecet::from_hex(0xABC);
assert_eq!(d.to_binary_string(), "101010111100");Trait Implementations§
Source§impl Ord for Dodecet
impl Ord for Dodecet
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Dodecet
impl PartialOrd for Dodecet
impl Copy for Dodecet
impl Eq for Dodecet
impl StructuralPartialEq for Dodecet
Auto Trait Implementations§
impl Freeze for Dodecet
impl RefUnwindSafe for Dodecet
impl Send for Dodecet
impl Sync for Dodecet
impl Unpin for Dodecet
impl UnsafeUnpin for Dodecet
impl UnwindSafe for Dodecet
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