Rename to then_some and then

This commit is contained in:
varkor
2019-12-06 12:18:32 +00:00
parent 8579fe6fc3
commit 9f1269f23c
37 changed files with 57 additions and 57 deletions

View File

@@ -9,12 +9,12 @@ impl bool {
/// ```
/// #![feature(bool_to_option)]
///
/// assert_eq!(false.to_option(0), None);
/// assert_eq!(true.to_option(0), Some(0));
/// assert_eq!(false.then_some(0), None);
/// assert_eq!(true.then_some(0), Some(0));
/// ```
#[unstable(feature = "bool_to_option", issue = "64260")]
#[inline]
pub fn to_option<T>(self, t: T) -> Option<T> {
pub fn then_some<T>(self, t: T) -> Option<T> {
if self {
Some(t)
} else {
@@ -29,12 +29,12 @@ impl bool {
/// ```
/// #![feature(bool_to_option)]
///
/// assert_eq!(false.to_option_with(|| 0), None);
/// assert_eq!(true.to_option_with(|| 0), Some(0));
/// assert_eq!(false.then(|| 0), None);
/// assert_eq!(true.then(|| 0), Some(0));
/// ```
#[unstable(feature = "bool_to_option", issue = "64260")]
#[inline]
pub fn to_option_with<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
if self {
Some(f())
} else {

View File

@@ -1,7 +1,7 @@
#[test]
fn test_bool_to_option() {
assert_eq!(false.to_option(0), None);
assert_eq!(true.to_option(0), Some(0));
assert_eq!(false.to_option_with(|| 0), None);
assert_eq!(true.to_option_with(|| 0), Some(0));
assert_eq!(false.then_some(0), None);
assert_eq!(true.then_some(0), Some(0));
assert_eq!(false.then(|| 0), None);
assert_eq!(true.then(|| 0), Some(0));
}