#results #convenience #mostly-infallible

this-is-fine

pub type Fine<T, E> = (T, Result<(), E>); ☕🐕

1 unstable release

0.0.1 Sep 30, 2021

#43 in #convenience

Download history 14/week @ 2024-07-14 12/week @ 2024-07-21 17/week @ 2024-07-28 16/week @ 2024-08-04 18/week @ 2024-08-11 7/week @ 2024-08-18 24/week @ 2024-08-25 36/week @ 2024-09-01 18/week @ 2024-09-08 24/week @ 2024-09-15 70/week @ 2024-09-22 43/week @ 2024-09-29 92/week @ 2024-10-06 12/week @ 2024-10-13 60/week @ 2024-10-20 24/week @ 2024-10-27

188 downloads per month
Used in pinus

MIT/Apache

14KB
165 lines

this-is-fine

Lib.rs Crates.io Docs.rs

Rust 1.51 CI Crates.io - License

GitHub open issues open pull requests good first issues

crev reviews

☕🐕

Utilities for working with type Fine<T, E> = (T, Result<(), E>).

It's a useful return type for map and set insertions.

The API is mostly a port of Result<T, E>'s.

Installation

Please use cargo-edit to always add the latest version of this library:

cargo add this-is-fine

Example

This is a slightly incomplete API preview.

use this_is_fine::{Fine, prelude::*};

let fine: Fine<_, ()> = ((), Ok(()));

fine.fine(); // Discard any error.
fine.not_fine(); // Convert to `Result`.
fine.ok(); // `.not_fine().ok()`
fine.err(); // `.1.err()`
fine.is_ok(); // `.1.is_ok()`
fine.is_err(); // `.1.is_err()`
fine.as_ref(); // Like `Result::as_ref`.
fine.map(|t| t); // Like `Result::map`.
fine.map_err(|e| e); // Like `Result::map_err`.
fine.expect("message"); // Like `.fine`, but can panic.
fine.unwrap(); // "

let mut fine = fine;
fine.as_mut(); // Like `Result::as_mut`.

// `Some` error is still fine.
let fine = this_is_fine::from_inverse(((), Some(())));
fine.expect_err("message");
fine.unwrap_err();
fine.fine();

// Twice as fine.
let fine_fine: Fine<Fine<_, ()>, ()> = (((), Ok(())), Ok(()));
fine_fine.transpose(); // Exchange `Result`s.

License

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.

See CONTRIBUTING for more information.

Code of Conduct

Changelog

Versioning

this-is-fine strictly follows Semantic Versioning 2.0.0 with the following exceptions:

  • The minor version will not reset to 0 on major version changes (except for v1).
    Consider it the global feature level.
  • The patch version will not reset to 0 on major or minor version changes (except for v0.1 and v1).
    Consider it the global patch level.

This includes the Rust version requirement specified above.
Earlier Rust versions may be compatible, but this can change with minor or patch releases.

Which versions are affected by features and patches can be determined from the respective headings in CHANGELOG.md.

No runtime deps