mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 00:01:34 +11:00
Default implementations (#571)
Add some implementations of `Default` for classes with empty new constructors - [x] Changelog updated
This commit is contained in:
commit
2c8cb646ac
|
@ -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.
|
||||
|
|
|
@ -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()));
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue