A checked Rust type for an IDL type
rust_typeinbuild.rsholds an IDL declaration as a Rust type of your own (GitHub #33): an IDLstringas a date-time group that cannot hold an invalid one, anunsigned longkey asNonZeroU32.
- Example:
rust-type - Repository: zero-dds-snippets
What it shows
build.rscallszerodds_build::Config::new().rust_type("app::Dtg", "crate::dtg::Dtg").rust_type("app::Track.id", "core::num::NonZeroU32"); a path that names no typedef, member or union branch is a build error.Dtgimplementszerodds_wire::WireReprwithtype Idl = str: it writes throughDisplaystraight into the sample's buffer and reads from the&strthe received sample lends.- A C or C++ peer built from
idl/track.idlsees thestringand theuint32and reads the same octets. - Two samples are rejected with their reasons: a time that is no date-time group, and a key of zero.
Build and run
cargo run
Output
83 octets: 070000000d0000003035313433305a4e4f5632360000000029000000020000000d0000003035313430305a4e4f563236000000000d0000003035313431355a4e4f5632360000000007000000414c5048413100
read back: 7 at 051430ZNOV26
rejected: at 4: expected a date-time group DDHHMMZMONYY
rejected: at 0: expected a value other than zero, which a `NonZero<u32>` holds
Output of a run on the Linux test host with ci/run-examples.sh.
The crates of GitHub #33 are newer than the latest crates.io release: the example reaches them through path dependencies into a ZeroDDS source tree that holds the snippets repository, until RC8 publishes them.
See also
- rust-derive, the same type defined in Rust
- zerodds-build
Ein geprüfter Rust-Typ für einen IDL-Typ
rust_typeinbuild.rshält eine IDL-Deklaration als eigenen Rust-Typ (GitHub #33): einen IDL-stringals Datum-Zeit-Gruppe, die keine ungültige halten kann, einen Key vom Typunsigned longalsNonZeroU32.
- Beispiel:
rust-type - Repository: zero-dds-snippets
Was es zeigt
build.rsruftzerodds_build::Config::new().rust_type("app::Dtg", "crate::dtg::Dtg").rust_type("app::Track.id", "core::num::NonZeroU32")auf; ein Pfad, der keinen Typedef, kein Member und keinen Union-Zweig nennt, ist ein Build-Fehler.Dtgimplementiertzerodds_wire::WireReprmittype Idl = str: Es schreibt überDisplaydirekt in den Puffer des Samples und liest aus dem&str, den das empfangene Sample leiht.- Ein C- oder C++-Gegenüber, aus
idl/track.idlgebaut, sieht denstringund denuint32und liest dieselben Oktette. - Zwei Samples werden mit ihrem Grund abgelehnt: eine Zeit, die keine Datum-Zeit-Gruppe ist, und ein Key von null.
Bauen und ausführen
cargo run
Ausgabe
83 octets: 070000000d0000003035313433305a4e4f5632360000000029000000020000000d0000003035313430305a4e4f563236000000000d0000003035313431355a4e4f5632360000000007000000414c5048413100
read back: 7 at 051430ZNOV26
rejected: at 4: expected a date-time group DDHHMMZMONYY
rejected: at 0: expected a value other than zero, which a `NonZero<u32>` holds
Ausgabe eines Laufs auf dem Linux-Testhost mit ci/run-examples.sh.
Die Crates zu GitHub #33 sind neuer als das letzte Release auf crates.io: Das Beispiel erreicht sie über Pfadabhängigkeiten in einen ZeroDDS-Quellbaum, der das Snippets-Repository enthält, bis RC8 sie veröffentlicht.
Verwandt
- rust-derive, derselbe Typ in Rust definiert
- zerodds-build