-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Example:
use thousands::{digits::ASCII_HEXADECIMAL, Separable, SeparatorPolicy};
pub fn display_hex_offset<T: std::fmt::LowerHex + num_traits::PrimInt + std::fmt::Display>(
offset: T,
) -> String {
let hex_display_policy = SeparatorPolicy {
separator: "_",
groups: &[4],
digits: ASCII_HEXADECIMAL,
};
offset.separate_by_policy(hex_display_policy)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_display_hex_offset() {
assert_eq!(display_hex_offset(0), "0"); // Passes
assert_eq!(display_hex_offset(1), "1"); // Passes
assert_eq!(display_hex_offset(10), "A"); // Fails, got "10"
assert_eq!(display_hex_offset(15), "F"); // Fails, got "15"
assert_eq!(display_hex_offset(16), "10");
assert_eq!(display_hex_offset(4096), "1000");
assert_eq!(display_hex_offset(268435455), "FFF_FFFF");
assert_eq!(display_hex_offset(0xFFFF_FFFF_u64), "FFFF_FFFF");
}
}If I'm doing it wrong, you should add an example to the README.
Version = 0.2.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels