Skip to content

Commit

Permalink
Add a take method to Optional
Browse files Browse the repository at this point in the history
This makes it easier to take ownership of optional values inside the `&'static mut BootInfo`.
  • Loading branch information
phil-opp committed Dec 29, 2023
1 parent 7d2a579 commit 2db7ae2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/src/info.rs
Original file line number Diff line number Diff line change
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 2db7ae2

Please sign in to comment.