Tracking Issue for producing a Result<(), E> from a bool (original) (raw)

Feature gate: #![feature(bool_to_result)]

This is a tracking issue for adding bool::ok_or and bool::ok_or_else as discussed in rust-lang/libs-team#606

This feature allows you to directly produce a Result<(), E> from a bool and is a short-hand for .then_some(()).ok_or(...) or .then_some(()).ok_or_else(|| ...).

Public API

assert_eq!(false.ok_or(0), Err(0)); assert_eq!(true.ok_or(0), Ok(()));

assert_eq!(false.ok_or_else(|| 0), Err(0)); assert_eq!(true.ok_or_else(|| 0), Ok(()));

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html