Skip to content

Commit

Permalink
Merge pull request #411 from rust-osdev/optional-take
Browse files Browse the repository at this point in the history
Add a `take` method to `Optional`
  • Loading branch information
phil-opp committed Dec 29, 2023
2 parents 7d2a579 + 2db7ae2 commit 751585c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/src/info.rs
Expand Up @@ -341,6 +341,11 @@ impl<T> Optional<T> {
Self::None => None,
}
}

/// Takes the value out of the `Optional`, leaving a `None` in its place.
pub fn take(&mut self) -> Option<T> {
core::mem::replace(self, Optional::None).into_option()
}
}

impl<T> From<Option<T>> for Optional<T> {
Expand Down

0 comments on commit 751585c

Please sign in to comment.