From 941eb4ade10918bbea0336072ca91488ef2fccf8 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 28 Feb 2024 09:55:55 +0000 Subject: [PATCH 1/3] Add missing default implementations --- agb/src/rng.rs | 6 ++++++ agb/src/sync/locks.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/agb/src/rng.rs b/agb/src/rng.rs index f0ef404f..b98ad6ce 100644 --- a/agb/src/rng.rs +++ b/agb/src/rng.rs @@ -52,6 +52,12 @@ impl RandomNumberGenerator { } } +impl Default for RandomNumberGenerator { + fn default() -> Self { + Self::new() + } +} + static GLOBAL_RNG: Mutex> = Mutex::new(RefCell::new(RandomNumberGenerator::new())); diff --git a/agb/src/sync/locks.rs b/agb/src/sync/locks.rs index fdb7033f..18155522 100644 --- a/agb/src/sync/locks.rs +++ b/agb/src/sync/locks.rs @@ -60,6 +60,12 @@ impl RawMutex { unsafe impl Send for RawMutex {} unsafe impl Sync for RawMutex {} +impl Default for RawMutex { + fn default() -> Self { + Self::new() + } +} + /// A guard representing an active lock on an [`RawMutex`]. pub struct RawMutexGuard<'a>(&'a RawMutex); impl<'a> Drop for RawMutexGuard<'a> { From 661eb7155f13f793432756eaf64c53a432a2ab49 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 28 Feb 2024 09:56:23 +0000 Subject: [PATCH 2/3] Add changelog entry for default implementations --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9547ff7..4170e01c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +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`. ### Change - A few functions which previously accepted a `Vector` now accept an `impl Into>` instead. From 42eadde631d1d68c52e4fc5981b360764fb3891a Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 28 Feb 2024 10:09:12 +0000 Subject: [PATCH 3/3] 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() {