chain-assertions 0.1.2

Insertable assertions into method chains
Documentation
  • Coverage
  • 84%
    21 out of 25 items documented15 out of 22 items with examples
  • Size
  • Source code size: 47.18 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.28 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • mezum/chain-assertions-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mezum

chain-assertions

Repository Latest Version Documentations License MSRV Coverage CI

This crate provides the assertion that can be insert between method chains.

Usage

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");

Motivation

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.

License

Copyright (c) 2025 Kitsunesaki Mezumona

Licensed under either of

at your option.

Contribution

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.