The robotics feature allows parsing of YAML extensions used in robotics (like ROS), including mathematical expressions and angle conversions (e.g., deg(180), rad(pi), or 1 + 2*(3 - 4/5)).
To use this capability, you must perform two steps:
- Enable the
robotics feature in your Cargo.toml. - Set
angle_conversions: true in the serde_saphyr::options! macro.
Note: This is a simple expression calculator implemented in Rust, not a full language interpreter. Safety hardening is included to limit expression depth, digit counts, and fraction precision.
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct RoboFloats {
func_deg: f64,
func_rad: f64,
}
fn main() {
let yaml = "func_deg: deg(180)\nfunc_rad: rad(pi)\n";
let options = serde_saphyr::options! {
angle_conversions: true,
};
let v: RoboFloats = serde_saphyr::from_str_with_options(yaml, options)
.expect("parse robotics YAML");
assert!((v.func_deg - std::f64::consts::PI).abs() < 1e-12);
assert!((v.func_rad - std::f64::consts::PI).abs() < 1e-12);
}