util: WithLifetime type for tagging with a lifetime
This commit is contained in:
parent
5814118d3f
commit
f3cc43e49e
|
@ -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<T> 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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue