You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rust-api.md 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Rust API
  2. ## Operator
  3. The operator API is a framework for you to implement. The implemented operator will be managed by `dora`. This framework enable us to make optimisation and provide advanced features. It is the recommended way of using `dora`.
  4. An operator requires to be registered and implement the `DoraOperator` trait. It is composed of an `on_event` method that defines the behaviour of the operator when there is an event such as receiving an input for example.
  5. ```rust
  6. {{#include ../../examples/rust-dataflow/operator/src/lib.rs:0:17}}
  7. ```
  8. ### Try it out!
  9. - Generate a new Rust library
  10. ```bash
  11. cargo new rust-dataflow-example-operator --lib
  12. ```
  13. `Cargo.toml`
  14. ```toml
  15. {{#include ../../examples/rust-dataflow/operator/Cargo.toml}}
  16. ```
  17. `src/lib.rs`
  18. ```rust
  19. {{#include ../../examples/rust-dataflow/operator/src/lib.rs}}
  20. ```
  21. - Build it:
  22. ```bash
  23. cargo build --release
  24. ```
  25. - Link it in your graph as:
  26. ```yaml
  27. {{#include ../../examples/rust-dataflow/dataflow.yml:13:21}}
  28. ```
  29. This example can be found in `examples`.
  30. ## Custom Node
  31. The custom node API allow you to integrate `dora` into your application. It allows you to retrieve input and send output in any fashion you want.
  32. #### `DoraNode::init_from_env()`
  33. `DoraNode::init_from_env()` initiate a node from environment variables set by `dora-coordinator`
  34. ```rust
  35. let (mut node, mut events) = DoraNode::init_from_env()?;
  36. ```
  37. #### `.recv()`
  38. `.recv()` wait for the next event on the events stream.
  39. ```rust
  40. let event = events.recv();
  41. ```
  42. #### `.send_output(...)`
  43. `send_output` send data from the node to the other nodes.
  44. We take a closure as an input to enable zero copy on send.
  45. ```rust
  46. node.send_output(
  47. &data_id,
  48. metadata.parameters,
  49. data.len(),
  50. |out| {
  51. out.copy_from_slice(data);
  52. })?;
  53. ```
  54. ### Try it out!
  55. - Generate a new Rust binary (application):
  56. ```bash
  57. cargo new rust-dataflow-example-node
  58. ```
  59. ```toml
  60. {{#include ../../examples/rust-dataflow/node/Cargo.toml}}
  61. ```
  62. `src/main.rs`
  63. ```rust
  64. {{#include ../../examples/rust-dataflow/node/src/main.rs}}
  65. ```
  66. - Link it in your graph as:
  67. ```yaml
  68. {{#include ../../examples/rust-dataflow/dataflow.yml:6:12}}
  69. ```

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed datafl