diff --git a/CHANGELOG.md b/CHANGELOG.md index f9547ff7..49200d0e 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`, `InitOnce` and `RawMutex`. ### Change - A few functions which previously accepted a `Vector` now accept an `impl Into>` instead. 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..2c2cd952 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> { @@ -136,6 +142,7 @@ pub struct InitOnce { is_initialized: Static, value: UnsafeCell>, } + impl InitOnce { /// Creates a new uninitialized object. #[must_use] @@ -195,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() {