Also add default implementation for InitOnce

This commit is contained in:
Gwilym Inzani 2024-02-28 10:09:12 +00:00
parent 661eb7155f
commit 42eadde631
2 changed files with 9 additions and 1 deletions

View file

@ -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. - 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. - 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. - 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 ### Change
- A few functions which previously accepted a `Vector<u16>` now accept an `impl Into<Vector2D<u16>>` instead. - A few functions which previously accepted a `Vector<u16>` now accept an `impl Into<Vector2D<u16>>` instead.

View file

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