remove unused code and allow dead code

This commit is contained in:
Corwin Kuiper 2021-04-11 16:35:49 +01:00 committed by Corwin
parent fe4bc7274a
commit 14c46374fa

View file

@ -2,6 +2,7 @@ pub struct Singleton<T> {
single: Option<T>, single: Option<T>,
} }
#[allow(dead_code)]
impl<T> Singleton<T> { impl<T> Singleton<T> {
pub const fn new(s: T) -> Self { pub const fn new(s: T) -> Self {
Singleton { single: Some(s) } Singleton { single: Some(s) }
@ -13,39 +14,4 @@ impl<T> Singleton<T> {
let g = core::mem::replace(&mut self.single, None); let g = core::mem::replace(&mut self.single, None);
g.unwrap() g.unwrap()
} }
pub fn ret(&mut self, ret: T) {
self.single = Some(ret);
}
}
pub struct Single {
is_taken: bool,
}
pub struct SingleToken<'a> {
cell: &'a mut bool,
}
impl Single {
pub const fn new() -> Self {
Single { is_taken: false }
}
pub fn take(&mut self) -> Result<SingleToken, &'static str> {
if self.is_taken {
Err("Already taken")
} else {
self.is_taken = true;
Ok(SingleToken {
cell: &mut self.is_taken,
})
}
}
}
impl Drop for SingleToken<'_> {
fn drop(&mut self) {
(*self.cell) = false;
}
} }