Expand description
Generate a compile-time object dictionary from an EDS/DCF file (for build.rs).
Cross-platform. Generate a compile-time object dictionary from an EDS/DCF file.
generate_object_dictionary
emits Rust source for a function that builds a
canopen_rs::ObjectDictionary populated from a parsed
Eds. Run it from a build.rs so a device’s .eds
becomes a typed, zero-runtime-parse OD:
ⓘ
// build.rs
use canopen_host::{codegen::generate_object_dictionary, eds::Eds};
use std::{env, fs, path::Path};
fn main() {
let eds = Eds::from_file("device.eds").unwrap();
let src = generate_object_dictionary(&eds, "device_od");
let out = Path::new(&env::var("OUT_DIR").unwrap()).join("device_od.rs");
fs::write(out, src).unwrap();
println!("cargo:rerun-if-changed=device.eds");
}ⓘ
// in your crate:
include!(concat!(env!("OUT_DIR"), "/device_od.rs"));
let od = device_od(); // ObjectDictionary<N>, ready to serveFunctions§
- generate_
object_ dictionary - Emit Rust source for a
pub fn <fn_name>() -> canopen_rs::ObjectDictionary<N>that inserts every object ineds, withNsized to fit exactly.