Add lifetimes to timers

This commit is contained in:
Gwilym Kuiper 2023-02-23 20:46:28 +00:00
parent 2bab48b422
commit 92066f7adb
2 changed files with 10 additions and 3 deletions

View file

@ -375,6 +375,7 @@ mod marker {
/// Allows access to the cartridge's save data. /// Allows access to the cartridge's save data.
#[non_exhaustive] #[non_exhaustive]
pub struct SaveManager {} pub struct SaveManager {}
impl SaveManager { impl SaveManager {
pub(crate) const fn new() -> Self { pub(crate) const fn new() -> Self {
SaveManager {} SaveManager {}

View file

@ -1,3 +1,5 @@
use core::marker::PhantomData;
use crate::memory_mapped::MemoryMapped; use crate::memory_mapped::MemoryMapped;
const fn timer_data(timer: usize) -> MemoryMapped<u16> { const fn timer_data(timer: usize) -> MemoryMapped<u16> {
@ -39,16 +41,20 @@ pub struct Timer {
} }
#[non_exhaustive] #[non_exhaustive]
pub struct Timers { pub struct Timers<'gba> {
pub timer2: Timer, pub timer2: Timer,
pub timer3: Timer, pub timer3: Timer,
phantom: PhantomData<&'gba ()>,
} }
impl Timers { impl Timers<'_> {
pub(crate) unsafe fn new() -> Self { pub(crate) unsafe fn new() -> Self {
Self { Self {
timer2: Timer::new(2), timer2: Timer::new(2),
timer3: Timer::new(3), timer3: Timer::new(3),
phantom: PhantomData,
} }
} }
} }
@ -129,7 +135,7 @@ impl TimerController {
Self {} Self {}
} }
pub fn timers(&mut self) -> Timers { pub fn timers(&mut self) -> Timers<'_> {
unsafe { Timers::new() } unsafe { Timers::new() }
} }
} }