mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
allow explicit drop of GeneralGuard
This commit is contained in:
committed by
Aiden McClelland
parent
93acf1b6a0
commit
5211f7b2a0
@@ -1031,17 +1031,21 @@ impl<T> Future for NonDetachingJoinHandle<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GeneralGuard<F: FnOnce()>(Option<F>);
|
||||
impl<F: FnOnce()> GeneralGuard<F> {
|
||||
pub struct GeneralGuard<F: FnOnce() -> T, T = ()>(Option<F>);
|
||||
impl<F: FnOnce() -> T, T> GeneralGuard<F, T> {
|
||||
pub fn new(f: F) -> Self {
|
||||
GeneralGuard(Some(f))
|
||||
}
|
||||
|
||||
pub fn drop(mut self) -> T {
|
||||
self.0.take().unwrap()()
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: FnOnce()> Drop for GeneralGuard<F> {
|
||||
impl<F: FnOnce() -> T, T> Drop for GeneralGuard<F, T> {
|
||||
fn drop(&mut self) {
|
||||
if let Some(destroy) = self.0.take() {
|
||||
destroy()
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user