Skip to content

feat(once): add Once::new_completed constructor#520

Open
SAY-5 wants to merge 1 commit into
Amanieu:masterfrom
SAY-5:feat-once-new-completed
Open

feat(once): add Once::new_completed constructor#520
SAY-5 wants to merge 1 commit into
Amanieu:masterfrom
SAY-5:feat-once-new-completed

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 21, 2026

Closes #441.

Adds Once::new_completed(), a const constructor that produces a Once already in the Done state. Naming follows @Amanieu's suggestion in the issue (new_completed for consistency with the standard library's Once::is_completed). Existing Once::new() semantics are unchanged.

static INIT: Once = Once::new_completed();
assert_eq!(INIT.state(), OnceState::Done);
INIT.call_once(|| unreachable!()); // closure is skipped

Tests cover the new constructor and a regression test that Once::new() still runs its closure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a method to Once to create an already-done Once

1 participant