Skip to content

Commit

Permalink
NoneOr::from_option
Browse files Browse the repository at this point in the history
Reviewed By: JakobDegen

Differential Revision: D63774249

fbshipit-source-id: d9a5a3c7571e31863193f88a92379c7487b99c13
  • Loading branch information
stepancheg authored and facebook-github-bot committed Oct 2, 2024
1 parent 5c3bb1f commit 1b790a8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions starlark/src/values/types/none/none_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ impl<T> NoneOr<T> {
}
}

/// Convert a Rust [`Option`] to a [`NoneOr`].
#[inline]
pub fn from_option(option: Option<T>) -> Self {
match option {
None => NoneOr::None,
Some(x) => NoneOr::Other(x),
}
}

/// Is the value a [`NoneOr::None`].
pub fn is_none(&self) -> bool {
matches!(self, NoneOr::None)
Expand Down

0 comments on commit 1b790a8

Please sign in to comment.