then 0.1.0

bool::then functions but named properly
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented3 out of 4 items with examples
  • Size
  • Source code size: 16.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.09 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • rossmacarthur/advent
    21 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rossmacarthur

then

Crates.io Version Docs.rs Latest Build Status

The standard library named bool::then_some and bool::then strangely. It should have been then and then_with. I find it annoying that expr.then(|| value) is shorter to type that the more “idiomatic” expr.then_some(value)

This crate provides these functions under the following names .some and .some_with.

Getting started

First, add the crate to your Cargo manifest.

cargo add then

Now bring the trait into scope.

use then::Some;

The .some and .some_with methods are now available on bool.

assert_eq!(false.some(0), None);
assert_eq!(true.some_with(Default::default), Some(0));

License

This project is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.