diff options
Diffstat (limited to 'ecs/src/lock.rs')
-rw-r--r-- | ecs/src/lock.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ecs/src/lock.rs b/ecs/src/lock.rs index c8a8495..b3c9f57 100644 --- a/ecs/src/lock.rs +++ b/ecs/src/lock.rs @@ -1,3 +1,4 @@ +use std::mem::transmute; use std::ops::{Deref, DerefMut}; use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard, TryLockError}; @@ -73,6 +74,21 @@ where inner: RwLockReadGuard<'guard, Value>, } +impl<'guard, Value> ReadGuard<'guard, Value> +where + Value: TypeName, +{ + /// Converts the `ReadGuard` to a `ReadGuard` with a possibly longer lifetime. + /// + /// # Safety + /// The returned `ReadGuard` must **NOT** be used for longer than the original + /// lifetime. + pub unsafe fn upgrade_lifetime<'new>(self) -> ReadGuard<'new, Value> + { + unsafe { transmute(self) } + } +} + impl<'guard, Value> Deref for ReadGuard<'guard, Value> where Value: TypeName, |