Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into eliza/saethlin/prov…
Browse files Browse the repository at this point in the history
…enance

This branch merges upstream's `master` branch into PR matklad#185.

I need to patch a dependency on `once_cell` that needs at least 1.13.0
to pick up the provenance fix, but you may want to actually merge this
into the PR as well.
  • Loading branch information
hawkw committed Jul 30, 2022
2 parents 4aa5ac4 + eda22ce commit ee55dd2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,14 @@

-

## 1.13.0

- Add `Lazy::get`, similar to `OnceCell::get`.

## 1.12.1

- Remove incorrect `debug_assert`.

## 1.12.0

- Add `OnceCell::wait`, a blocking variant of `get`.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "once_cell"
version = "1.12.0"
version = "1.13.0"
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2018"
Expand Down
1 change: 1 addition & 0 deletions src/imp_pl.rs
Expand Up @@ -168,6 +168,7 @@ fn initialize_inner(state: &AtomicU8, init: &mut dyn FnMut() -> bool) {
None,
);
},
Err(INCOMPLETE) => (),
Err(_) => debug_assert!(false),
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/lib.rs
Expand Up @@ -741,6 +741,23 @@ pub mod unsync {
None => panic!("Lazy instance has previously been poisoned"),
})
}

/// Gets the reference to the result of this lazy value if
/// it was initialized, otherwise returns `None`.
///
/// # Example
/// ```
/// use once_cell::unsync::Lazy;
///
/// let lazy = Lazy::new(|| 92);
///
/// assert_eq!(Lazy::get(&lazy), None);
/// assert_eq!(&*lazy, &92);
/// assert_eq!(Lazy::get(&lazy), Some(&92));
/// ```
pub fn get(this: &Lazy<T, F>) -> Option<&T> {
this.cell.get()
}
}

impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
Expand Down Expand Up @@ -1214,6 +1231,23 @@ pub mod sync {
None => panic!("Lazy instance has previously been poisoned"),
})
}

/// Gets the reference to the result of this lazy value if
/// it was initialized, otherwise returns `None`.
///
/// # Example
/// ```
/// use once_cell::sync::Lazy;
///
/// let lazy = Lazy::new(|| 92);
///
/// assert_eq!(Lazy::get(&lazy), None);
/// assert_eq!(&*lazy, &92);
/// assert_eq!(Lazy::get(&lazy), Some(&92));
/// ```
pub fn get(this: &Lazy<T, F>) -> Option<&T> {
this.cell.get()
}
}

impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
Expand Down

0 comments on commit ee55dd2

Please sign in to comment.