From 42eadde631d1d68c52e4fc5981b360764fb3891a Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 28 Feb 2024 10:09:12 +0000 Subject: [PATCH] Also add default implementation for InitOnce --- CHANGELOG.md | 2 +- agb/src/sync/locks.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4170e01c..49200d0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - An abstraction over hblank DMA to allow for cool effects like gradients and circular windows. See the dma_effect* examples. - Expermental and incomplete support for MIDI files with agb-tracker. - Fixnum now implements [`num::Num`](https://docs.rs/num/0.4/num/trait.Num.html) from the [`num`](https://crates.io/crates/num) crate. -- `Default` implementations for `RandomNumberGenerator` and `RawMutex`. +- `Default` implementations for `RandomNumberGenerator`, `InitOnce` and `RawMutex`. ### Change - A few functions which previously accepted a `Vector` now accept an `impl Into>` instead. diff --git a/agb/src/sync/locks.rs b/agb/src/sync/locks.rs index 18155522..2c2cd952 100644 --- a/agb/src/sync/locks.rs +++ b/agb/src/sync/locks.rs @@ -142,6 +142,7 @@ pub struct InitOnce { is_initialized: Static, value: UnsafeCell>, } + impl InitOnce { /// Creates a new uninitialized object. #[must_use] @@ -201,6 +202,13 @@ impl InitOnce { } } } + +impl Default for InitOnce { + fn default() -> Self { + Self::new() + } +} + impl Drop for InitOnce { fn drop(&mut self) { if self.is_initialized.read() {