#condition #apply #chain #meta #object #no-alloc

no-std apply_conditionally

Chain and apply methods on objects conditionally

2 stable releases

new 2.0.0 Apr 16, 2024
1.0.0 Mar 7, 2024

#832 in Rust patterns

MIT license

9KB
75 lines

Apply Conditionally

Chain and apply methods on objects conditionally.

Installation

  1. Using cargo:
cargo add apply_conditionally
  1. By updating Cargo.toml:
[dependencies]
apply_conditionally = "1.0.0"

Usage

// Bring the trait into scope to access the trait methods on objects
use apply_conditionally::ApplyConditionally;

fn foo<T>(value: T, condition: bool) {
    value
        .apply(bar)
        .apply_if(condition, baz)
        .some_other_method();
}

License

Licensed under the MIT License.


lib.rs:

Apply Conditionally

Chain and apply methods on objects conditionally.

Dependencies

~45KB