Function coap_numbers::code::format_dotted
source · pub fn format_dotted(code: u8, f: &mut Formatter<'_>) -> Result
Expand description
Format a CoAP code in dotted notation
This prints the class number of a code, followed by a dot and the two-digit detail, into a formatter. That format is the common human-readable expression of CoAP codes, as it eases the comparison to the (dot-less) codes of HTTP.
It is typically used to easily implement the Display trait on types that contain a code:
struct Code(u8);
impl core::fmt::Display for Code {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
format_dotted(self.0, f)?;
if let Some(name) = to_name(self.0) {
write!(f, " {}", name)?;
}
Ok(())
}
}
let g = format!("{}", Code(GET));
assert_eq!(g, "0.01 GET");