Download examples/multiple-daemons/operator/src/lib.rs from TomPei/csg-robomaster: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/datasets/TomPei/csg-robomaster/resolve/main/examples/multiple-daemons/operator/src/lib.rs
- Command line
-
hf download hf://datasets/TomPei/csg-robomaster/examples/multiple-daemons/operator/src/lib.rs
-
curl -L -o lib.rs https://huggingface.co/datasets/TomPei/csg-robomaster/resolve/main/examples/multiple-daemons/operator/src/lib.rs
1.6 kB
| use dora_operator_api::{ | |
| register_operator, DoraOperator, DoraOutputSender, DoraStatus, Event, IntoArrow, | |
| }; | |
| register_operator!(ExampleOperator); | |
| struct ExampleOperator { | |
| ticks: usize, | |
| } | |
| impl DoraOperator for ExampleOperator { | |
| fn on_event( | |
| &mut self, | |
| event: &Event, | |
| output_sender: &mut DoraOutputSender, | |
| ) -> Result<DoraStatus, String> { | |
| match event { | |
| Event::Input { id, data } => match *id { | |
| "tick" => { | |
| self.ticks += 1; | |
| } | |
| "random" => { | |
| let data = u64::try_from(data) | |
| .map_err(|err| format!("expected u64 message: {err}"))?; | |
| let output = format!( | |
| "operator received random value {data:#x} after {} ticks", | |
| self.ticks | |
| ); | |
| output_sender.send("status".into(), output.into_arrow())?; | |
| } | |
| other => eprintln!("ignoring unexpected input {other}"), | |
| }, | |
| Event::Stop => {} | |
| Event::InputClosed { id } => { | |
| println!("input `{id}` was closed"); | |
| if *id == "random" { | |
| println!("`random` input was closed -> exiting"); | |
| return Ok(DoraStatus::Stop); | |
| } | |
| } | |
| other => { | |
| println!("received unknown event {other:?}"); | |
| } | |
| } | |
| Ok(DoraStatus::Continue) | |
| } | |
| } | |