1use azure_iot_rs::MessageBody;
9use azure_iot_rs::{IoTHubMessageDispositionResult, IotHubModuleClient, ModuleEventCallback};
10
11struct PrintModuleEvents;
12
13impl ModuleEventCallback for PrintModuleEvents {
14 fn on_message(&mut self, msg: azure_iot_rs::IotHubMessage) -> IoTHubMessageDispositionResult {
15 match msg.body() {
16 MessageBody::Text(s) => println!("Received message text: {s}"),
17 MessageBody::Binary(b) => {
18 println!("Received message binary ({:?} {} bytes)", b, b.len())
19 }
20 }
21 IoTHubMessageDispositionResult::Accepted
22 }
23
24 fn on_module_twin(&mut self, state: azure_iot_rs::IotHubDeviceTwinUpdateState, data: &[u8]) {
25 println!(
26 "Received twin update ({state}): {}",
27 String::from_utf8_lossy(data)
28 );
29 }
30
31 fn on_confirmation(&mut self, _status: Result<(), azure_iot_rs::IotError>) {}
32}
33
34fn main() {
35 println!("azure-iot-rs example CLI — starting client...");
36
37 let mut client = IotHubModuleClient::try_new(PrintModuleEvents).unwrap();
38
39 println!("Client initialized. Entering work loop (Ctrl+C to exit)...");
40 client.do_work();
41}