Skip to content

Commit 1b790a8

Browse files
stepanchegfacebook-github-bot
authored andcommitted
NoneOr::from_option
Reviewed By: JakobDegen Differential Revision: D63774249 fbshipit-source-id: d9a5a3c7571e31863193f88a92379c7487b99c13
1 parent 5c3bb1f commit 1b790a8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

starlark/src/values/types/none/none_or.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ impl<T> NoneOr<T> {
5151
}
5252
}
5353

54+
/// Convert a Rust [`Option`] to a [`NoneOr`].
55+
#[inline]
56+
pub fn from_option(option: Option<T>) -> Self {
57+
match option {
58+
None => NoneOr::None,
59+
Some(x) => NoneOr::Other(x),
60+
}
61+
}
62+
5463
/// Is the value a [`NoneOr::None`].
5564
pub fn is_none(&self) -> bool {
5665
matches!(self, NoneOr::None)

0 commit comments

Comments
 (0)