From 9757f7ed54bca0fd907e9eea1b036ce16da7177a Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 23 Feb 2023 20:37:03 +0000 Subject: [PATCH] Add correct lifetimes to windows --- agb/src/display/mod.rs | 2 +- agb/src/display/window.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/agb/src/display/mod.rs b/agb/src/display/mod.rs index 90f78727..c2cd91f0 100644 --- a/agb/src/display/mod.rs +++ b/agb/src/display/mod.rs @@ -88,7 +88,7 @@ impl ObjectDistribution { pub struct WindowDist; impl WindowDist { - pub fn get(&mut self) -> Windows { + pub fn get(&mut self) -> Windows<'_> { Windows::new() } } diff --git a/agb/src/display/window.rs b/agb/src/display/window.rs index 1f8e41b1..b8705029 100644 --- a/agb/src/display/window.rs +++ b/agb/src/display/window.rs @@ -1,5 +1,7 @@ #![deny(missing_docs)] //! The window feature of the GBA. +use core::marker::PhantomData; + use crate::{fixnum::Rect, memory_mapped::MemoryMapped}; use super::{tiled::BackgroundID, DISPLAY_CONTROL, HEIGHT, WIDTH}; @@ -7,10 +9,11 @@ use super::{tiled::BackgroundID, DISPLAY_CONTROL, HEIGHT, WIDTH}; /// The windows feature of the Game Boy Advance can selectively display /// backgrounds or objects on the screen and can selectively enable and disable /// effects. This gives out references and holds changes before they can be committed. -pub struct Windows { +pub struct Windows<'a> { wins: [MovableWindow; 2], out: Window, obj: Window, + phantom: PhantomData<&'a ()>, } const REG_HORIZONTAL_BASE: *mut u16 = 0x0400_0040 as *mut _; @@ -26,12 +29,13 @@ pub enum WinIn { Win1, } -impl Windows { +impl<'a> Windows<'a> { pub(crate) fn new() -> Self { let s = Self { wins: [MovableWindow::new(), MovableWindow::new()], out: Window::new(), obj: Window::new(), + phantom: PhantomData, }; s.commit(); s