Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update PR matklad#185 to 1.13.0 #1

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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