Default implementations (#571)

Add some implementations of `Default` for classes with empty new
constructors

- [x] Changelog updated
This commit is contained in:
Gwilym Inzani 2024-02-28 10:17:03 +00:00 committed by GitHub
commit 2c8cb646ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 0 deletions

View file

@ -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<u16>` now accept an `impl Into<Vector2D<u16>>` instead.

View file

@ -52,6 +52,12 @@ impl RandomNumberGenerator {
}
}
impl Default for RandomNumberGenerator {
fn default() -> Self {
Self::new()
}
}
static GLOBAL_RNG: Mutex<RefCell<RandomNumberGenerator>> =
Mutex::new(RefCell::new(RandomNumberGenerator::new()));

View file

@ -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<T> {
is_initialized: Static<bool>,
value: UnsafeCell<MaybeUninit<T>>,
}
impl<T> InitOnce<T> {
/// Creates a new uninitialized object.
#[must_use]
@ -195,6 +202,13 @@ impl<T> InitOnce<T> {
}
}
}
impl<T> Default for InitOnce<T> {
fn default() -> Self {
Self::new()
}
}
impl<T> Drop for InitOnce<T> {
fn drop(&mut self) {
if self.is_initialized.read() {