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

no-std apply_conditionally

Chain and apply methods on objects conditionally

2 stable releases

2.0.0 Apr 16, 2024
1.0.0 Mar 7, 2024

#908 in Rust patterns

Download history 138/week @ 2024-03-07 6/week @ 2024-03-14 5/week @ 2024-03-28 3/week @ 2024-04-04 122/week @ 2024-04-11 18/week @ 2024-04-18

140 downloads per month

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