apply_integer

Function apply_integer 

Source
pub fn apply_integer(hint: &str, value: i32) -> Option<String>
Expand description

Apply RFC 2579 DISPLAY-HINT formatting to an integer value.

INTEGER hints have the form: <format>[-<decimal-places>]

Format characters:

  • d or d-N: Decimal, optionally with N implied decimal places
  • x: Lowercase hexadecimal
  • o: Octal
  • b: Binary

Returns None for invalid or unsupported hint formats.

ยงExamples

use async_snmp::format::display_hint;

// Basic formats
assert_eq!(display_hint::apply_integer("d", 1234), Some("1234".to_string()));
assert_eq!(display_hint::apply_integer("x", 255), Some("ff".to_string()));
assert_eq!(display_hint::apply_integer("o", 8), Some("10".to_string()));
assert_eq!(display_hint::apply_integer("b", 5), Some("101".to_string()));

// Decimal places (DISPLAY-HINT "d-2" means 2 implied decimal places)
assert_eq!(display_hint::apply_integer("d-2", 1234), Some("12.34".to_string()));
assert_eq!(display_hint::apply_integer("d-2", 5), Some("0.05".to_string()));
assert_eq!(display_hint::apply_integer("d-2", -500), Some("-5.00".to_string()));
assert_eq!(display_hint::apply_integer("d-1", 255), Some("25.5".to_string()));