Installation
Requirements
- Rust 1.85 or newer. The crate uses the Rust 2024 edition, which first shipped in
Rust 1.85. Check the installed version with
rustc --versionand update withrustup update stable. - Cargo, which comes with Rust. If you don’t have Rust yet, install it with rustup.
This crate is pure Rust with no system libraries to install, so it builds anywhere that Rust does, including Linux, macOS, and Windows.
Add the crate to your project
From your project’s directory, run:
cargo add open-dis-rust
Or add the dependency to Cargo.toml yourself:
[dependencies]
open-dis-rust = "1"
PDUs are encoded into a standard Vec<u8> and decoded from a &[u8], so you do not need
third-party crates to use them.
The package name uses hyphens, but in Rust code, the crate is referred to with underscores:
use open_dis_rust::entity_information::EntityStatePdu;
Async networking (optional)
The crate doesn’t depend on any networking library; however, the tokio crate is among
the gold standards of Rust networking and async I/O.
cargo add tokio --features full
The Quickstart guide uses std::net::UdpSocket, so tokio is not
needed to follow along.
Validate
To quickly test the crate, place the following code in your application’s src/main.rs:
use open_dis_rust::prelude::*;
use open_dis_rust::simulation_management::AcknowledgePdu;
fn main() {
let mut pdu = AcknowledgePdu::new();
let bytes = pdu.to_bytes().expect("serialize failed");
println!("open-dis-rust {} encoded the following {}-byte PDU: {:?}",
open_dis_rust::get_version(),
bytes.len(),
pdu
);
}
Then, execute cargo run to see a printout of the crate version and a view into the PDU.
Build from source
If you plan on contributing to the development of the crate, or if you want to modify the code for your own project, simply clone down the repo and build it yourself. You will need git and Rust.
git clone https://github.com/crhowell3/open-dis-rust.git
cd open-dis-rust
cargo build --release
cargo test -q
If you make modifications and wish to test them against personal projects, add this to your Cargo.toml:
[dependencies]
open-dis-rust = { path = "path/to/open-dis-rust" }
Read documentation offline
The API reference is published on docs.rs. To build it locally and open it in your browser:
cargo doc --open
To preview this book locally, install mdBook and
serve it from the book folder:
cargo install mdbook
mdbook serve book --open