#![deny(unsafe_op_in_unsafe_fn)]
#[cfg(test)]
pub(crate) mod test_device;
pub mod block;
pub mod caching_device;
pub mod callback_device;
#[cfg(feature = "cli")]
pub mod cli;
pub mod counting_device;
pub mod error;
pub mod ffi;
#[cfg(any(unix, windows))]
pub mod file_device;
pub mod readonly;
pub mod slice;
pub mod stream;
pub use block::{BlockDevice, BlockRead};
pub use caching_device::CachingDevice;
pub use callback_device::{CallbackDevice, FlushCb, ReadCb, WriteCb};
pub use counting_device::CountingDevice;
pub use error::{Error, Result};
#[cfg(any(unix, windows))]
pub use file_device::FileDevice;
pub use readonly::ReadOnlyDevice;
pub use slice::{OwnedRwSlice, OwnedSlice, SliceReader};
pub use stream::BlockReadStreamer;
#[cfg(test)]
mod overflow_checks {
const HANDSHAKE: &str = "EXPECT_OVERFLOW_CHECKS";
fn this_build_traps_an_overflow() -> bool {
let previous = std::panic::take_hook();
std::panic::set_hook(Box::new(|_| {}));
let trapped = std::panic::catch_unwind(|| {
let big = std::hint::black_box(u64::MAX);
std::hint::black_box(big + 1);
})
.is_err();
std::panic::set_hook(previous);
trapped
}
#[test]
fn the_build_the_gate_asked_to_check_does_check() {
let asked = match std::env::var(HANDSHAKE) {
Ok(value) if !value.is_empty() => value,
_ => return,
};
assert!(
this_build_traps_an_overflow(),
"{HANDSHAKE}={asked} was set, so this run is the one that is \
supposed to panic on arithmetic overflow -- and it did not. \
The checks are off in the profile the gate built. Something \
turned them off where nothing reading Cargo.toml can see it: \
a CARGO_PROFILE_TEST_OVERFLOW_CHECKS variable at step or job \
level, a .cargo/config.toml, or a cargo mechanism newer than \
this comment. The debug step is running and blind, which is \
the exact state it exists to rule out."
);
}
}