From 2db7ae29d110ccef4f4feef7cb3603722662e4a4 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 29 Dec 2023 20:15:35 +0100 Subject: [PATCH] Add a `take` method to `Optional` This makes it easier to take ownership of optional values inside the `&'static mut BootInfo`. --- api/src/info.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/src/info.rs b/api/src/info.rs index 965fcf40..81c849d8 100644 --- a/api/src/info.rs +++ b/api/src/info.rs @@ -341,6 +341,11 @@ impl Optional { Self::None => None, } } + + /// Takes the value out of the `Optional`, leaving a `None` in its place. + pub fn take(&mut self) -> Option { + core::mem::replace(self, Optional::None).into_option() + } } impl From> for Optional {