Skip to content

Commit

Permalink
bug repro
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Aug 4, 2018
1 parent 50141d3 commit ea1c14b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,28 @@ pub mod unsync {
pub mod sync {
// Can't use `OnceCell(imp::OnceCell) due to
// https://github.com/rust-lang/rust/issues/50518
pub use imp::OnceCell;
// pub use imp::OnceCell;
#[derive(Debug)]
pub struct OnceCell<T>(::imp::OnceCell<T>);

impl<T> OnceCell<T> {
pub const INIT: OnceCell<T> = OnceCell(::imp::OnceCell::INIT);
pub fn new() -> OnceCell<T> {
OnceCell(::imp::OnceCell::new())
}

pub fn get(&self) -> Option<&T> {
self.0.get()
}

pub fn set(&self, value: T) -> Result<(), T> {
self.0.set(value)
}

pub fn get_or_init<F: FnOnce() -> T>(&self, f: F) -> &T {
self.0.get_or_init(f)
}
}

/// A value which is initialized on the first access.
///
Expand Down

0 comments on commit ea1c14b

Please sign in to comment.