#no-std #map-if #do-if #filter-if

no-std apply_if

Conditionally apply a closure to an item or return it

1 stable release

Uses old Rust 2015

1.0.0 Dec 18, 2023

#832 in Development tools

24 downloads per month

MIT/Apache

3KB

ApplyIf

ApplyIf supplies a trait with one method: apply_if(cond, closure), that applies the closure on an object if the condition is true, returning the original object otherwise.
Very useful for the builder pattern when you want to keep the nice .builder1().builder2() chain, and not interrupt it with if-else blocks.

Comes with a blanket implementation for all sized types.


lib.rs:

ApplyIf

ApplyIf supplies a trait with one method: apply_if(cond, closure), that applies the closure on an object if the condition is true, returning the original object otherwise. Very useful for the builder pattern when you want to keep the nice .builder1().builder2() chain, and not interrupt it with if-else blocks.

//! Comes with a blanket implementation for all sized types.

No runtime deps