diff --git a/crates/renderer/src/util.rs b/crates/renderer/src/util.rs index b2cf3aa..316b657 100644 --- a/crates/renderer/src/util.rs +++ b/crates/renderer/src/util.rs @@ -1,4 +1,4 @@ -use std::ops::Deref; +use std::ops::{Deref, DerefMut}; use ash::vk; @@ -391,3 +391,26 @@ pub fn image_aspect_from_format(format: vk::Format) -> vk::ImageAspectFlags { _ => ImageAspectFlags::COLOR, } } + +#[repr(transparent)] +pub struct WithLifetime<'a, T>(T, std::marker::PhantomData<&'a ()>); + +impl WithLifetime<'_, T> { + pub fn new(t: T) -> Self { + Self(t, std::marker::PhantomData) + } +} + +impl<'a, T: 'a> Deref for WithLifetime<'a, T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<'a, T: 'a> DerefMut for WithLifetime<'a, T> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +}