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 documentation for Once to reference std::sync::OnceLock. #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//!
//! # Features
//!
//! - `Mutex`, `RwLock`, `Once`/`SyncOnceCell`, and `SyncLazy` equivalents
//! - `Mutex`, `RwLock`, `OnceLock`, and `LazyLock` equivalents
//!
//! - Support for `no_std` environments
//!
Expand Down Expand Up @@ -39,8 +39,6 @@
//!
//! - Guards support [leaking](https://doc.rust-lang.org/nomicon/leaking.html).
//!
//! - [`Once`] owns the value returned by its `call_once` initializer.
//!
Comment on lines -42 to -43
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for removing this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, we were comparing spin::Once to std::sync::Once, which didn't own the result of the initializer. Now we're comparing it to OnceLock, which does own the result of the initializer.

//! - [`RwLock`] supports counting readers and writers.
//!
//! Conversely, the types in this crate do not have some of the features `std::sync` has:
Expand Down
4 changes: 1 addition & 3 deletions src/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use core::{cell::UnsafeCell, fmt, marker::PhantomData, mem::MaybeUninit};

/// A primitive that provides lazy one-time initialization.
///
/// Unlike its `std::sync` equivalent, this is generalized such that the closure returns a
/// value to be stored by the [`Once`] (`std::sync::Once` can be trivially emulated with
/// `Once`).
/// This is analogous to `std::sync::OnceLock`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think this is probably too strong a statement. They're definitely very similar, but the APIs differ enough that I'd probably go for something like:

This type has similar behaviour to `std::sync::OnceLock`.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous "equivalent" was already much stronger language than "analogous," which isn't any stronger of a statement than "similar behavio[u]r." For most people, if they need a spinlock variant of std::sync::OnceLock then they'll consider spin::Once.

///
/// Because [`Once::new`] is `const`, this primitive may be used to safely initialize statics.
///
Expand Down