Skip to main content

from_u16

Function from_u16 

Source
pub fn from_u16(id: u16) -> Result<String, &'static str>
Available on crate feature std only.
Expand description

Converts a u16 integer ID back into its 2-character string representation.

The ID must be within the valid range (0 to 8835, inclusive). Uses the inverse of Base-94 encoding: c1 = (id / 94) + 0x21, c2 = (id % 94) + 0x21

§Arguments

  • id: The u16 integer ID to convert (0-8835).

§Returns

A Result containing the 2-character string ID, or an error message if the ID is out of range.

§Examples

use pk_command::msg_id;
assert_eq!(msg_id::from_u16(0), Ok("!!".to_string()));
assert_eq!(msg_id::from_u16(1), Ok("!\"".to_string()));
assert_eq!(msg_id::from_u16(94), Ok("\"!".to_string()));
assert_eq!(msg_id::from_u16(8835), Ok("~~".to_string()));

assert!(msg_id::from_u16(8836).is_err()); // out of range