| Crates.io | chain-assertions |
| lib.rs | chain-assertions |
| version | 0.1.2 |
| created_at | 2025-11-13 00:50:24.549618+00 |
| updated_at | 2025-11-13 13:32:21.207998+00 |
| description | Insertable assertions into method chains |
| homepage | |
| repository | https://github.com/mezum/chain-assertions-rs |
| max_upload_size | |
| id | 1930205 |
| size | 47,685 |
This crate provides the assertion that can be insert between method chains.
Install the crate into your Cargo.toml:
[dependencies]
chain-assertions = "0.1"
# Add `passthrough` to disable checking on debug builds.
# chain-assertions = { version = "0.1", features = ["disable"] }
# Set default-features to false in no-std environment:
# chain-assertions = { version = "0.1", default-features = false }
and then use it like following:
use chain_assertions::prelude::*;
let target = i32::from_str_radix("21", 10)
.debug_assert_ok()
.map(|v| v * 2);
assert_eq!(target, Ok(42));
use chain_assertions::prelude::*;
let target = i32::from_str_radix("foobar", 10)
.debug_assert_ok()
// ^-- panic occurred here if debug_assertion is enabled
// but if debug_assertion is disabled, no error happened.
.map(|v| v * 2);
assert!(matches!(target, Err(_)), "Should be Err");
This crate makes it easy to declare and validate intermediate assumptions in Result/Option method chains.
It panics in debug builds for rapid feedback, and in release builds it minimizes runtime overhead and favors fail-safe behavior to avoid unexpected panics.
This is especially useful for applications (e.g., games) where avoiding mid-run panics is important.
Copyright (c) 2025 Kitsunesaki Mezumona
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.