Function coap_numbers::option::get_criticality
source · pub fn get_criticality(option: u16) -> Criticality
Expand description
Extract the option’s critical/elective bit
assert_eq!(get_criticality(OBSERVE), Criticality::Elective);
assert_eq!(get_criticality(URI_HOST), Criticality::Critical);
Examples found in repository?
examples/options.rs (line 20)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() -> Result<(), std::num::ParseIntError> {
let mut options = std::env::args();
let _progname = options.next();
let options: Vec<u16> = options.map(|a| a.parse()).collect::<Result<_, _>>()?;
println!("Processing option numbers {:?}", options);
let mut path = "".to_string();
use coap_numbers::option;
for o in options {
match (o, option::get_criticality(o)) {
(option::URI_HOST, _) => {
/* Ignoring: We don't do virtual hosting here */
}
(option::URI_PATH, _) => {
path.push_str("/something");
}
(option::ETAG, _) => {
println!("ETag was set, I might not even need to respond in the end");
}
(o, option::Criticality::Elective) => {
println!("Elective option {} seen -- logging it because we might want to add support for it, but proceeding anyway", o);
}
(o, option::Criticality::Critical) => {
panic!("Encountered a critical option {}, erring out with BAD_OPTION", o);
}
}
}
println!("Message processed, request was for {}", path);
Ok(())
}