![License] ![Latest Version] ![Documentation]
This library wraps around the bspc Quake utility tool to make it easier to use it from Rust. It does so by spawning a child process and asynchronously waiting for its output.
Some features include:
OptionsBuilder::log_stream
)The BSPC tool itself is not included with the library. Instead, it needs to already exist in the filesystem before the library is used.
Basic example showing the conversion of a Quake BSP file to a MAP file:
```rs use bspc::{Command, Options}; use tokio_util::sync::CancellationToken;
let bspcontents = b"..."; let result = bspc::convert( "./path/to/bspc.exe", Command::BspToMap(bspcontents), Options::builder() .verbose(true) .build(), ) .await; match result { Ok(output) => { asserteq!(output.files.len(), 1); println!("{}", output.files[0].name); println!("{}", String::fromutf8_lossy(&output.files[0].contents)); } Err(err) => { println!("Conversion failed: {}", err); } } ```
The following snippet demonstrates how to cancel the conversion (in this case, using a timeout) via the cancellation token. Note that the cancellation is not done simply by dropping the future (as is normally done), since we want to ensure that the child process is killed and the temporary directory deleted before the future completes.
```rust use bspc::{Command, Options, ConversionError}; use tokio_util::sync::CancellationToken;
let bspcontents = b"..."; let canceltoken = CancellationToken::new(); let canceltask = { let canceltoken = canceltoken.clone(); tokio::spawn(async move { tokio::time::sleep(std::time::Duration::frommillis(10)).await; canceltoken.cancel(); }) }; let result = bspc::convert( "./path/to/bspc.exe", Command::BspToMap(bspcontents), Options::builder() .verbose(true) .cancellationtoken(canceltoken) .build(), ) .await; match result { Ok(output) => { asserteq!(output.files.len(), 1); println!("{}", output.files[0].name); println!("{}", String::fromutf8_lossy(&output.files[0].contents)); } Err(ConversionError::Cancelled) => { println!("Conversion timed out after 10 seconds"); } Err(err) => { println!("Conversion failed: {}", err); } } ```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.