|
| 1 | +//! This module provides the trait [`StructuredParameters`] default implementations for declaring parameters in structured fashion. |
| 2 | +//! [`rclrs_proc_macros::StructuredParameters`] provides a macro to derive the trait for structs automatically. |
| 3 | +//! |
| 4 | +//! # Example |
| 5 | +//! ``` |
| 6 | +//! use rclrs::*; |
| 7 | +//! use rclrs_proc_macros::StructuredParameters; |
| 8 | +//! |
| 9 | +//! #[derive(StructuredParameters, Debug)] |
| 10 | +//! pub struct SimpleStructuredParameters { |
| 11 | +//! #[param(description = "optional parameter description")] |
| 12 | +//! pub optional: rclrs::OptionalParameter<f64>, |
| 13 | +//! } |
| 14 | +//! #[derive(StructuredParameters, Debug)] |
| 15 | +//! pub struct NestedStructuredParameters { |
| 16 | +//! pub simple: SimpleStructuredParameters, |
| 17 | +//! #[param(default = Arc::from("test"))] |
| 18 | +//! pub mandatory: rclrs::MandatoryParameter<Arc<str>>, |
| 19 | +//! } |
| 20 | +//! let args: Vec<String> = [ |
| 21 | +//! "test", "--ros-args", |
| 22 | +//! "-p", "mandatory:=override", |
| 23 | +//! "-p", "simple.optional:=3.14", |
| 24 | +//! ].into_iter().map(str::to_string).collect(); |
| 25 | +//! let context = crate::Context::new(args, rclrs::InitOptions::default()).unwrap(); |
| 26 | +//! let exec = context.create_basic_executor(); |
| 27 | +//! let node = exec.create_node(rclrs::NodeOptions::new("test")).unwrap(); |
| 28 | +//! let params: NestedStructuredParameters = |
| 29 | +//! node.declare_parameters("").unwrap(); |
| 30 | +//! let param = params.simple.optional.get(); |
| 31 | +//! println!("{:?}", param) |
| 32 | +//! ``` |
| 33 | +
|
1 | 34 | use crate::NodeState;
|
2 | 35 |
|
3 | 36 | /// Marker trait for implementing [`StructuredParameters`] where a default value cannot be specified.
|
|
0 commit comments