simplify generational box by compressing debug info

This commit is contained in:
Jonathan Kelley committed 2024-01-22 21:17:02 -08:00
1 parent 27f8377ea5
commit 079fec3be6
7 files changed
+162 -163

No files matched your search

+5 -12
View File
@@ -6,22 +6,16 @@ use crate::{
use std::cell::{Ref, RefCell, RefMut};
/// A unsync storage. This is the default storage type.
#[derive(Default)]
pub struct UnsyncStorage(RefCell<Option<Box<dyn std::any::Any>>>);
impl Default for UnsyncStorage {
fn default() -> Self {
Self(RefCell::new(None))
}
}
impl<T: 'static> Storage<T> for UnsyncStorage {
type Ref<R: ?Sized + 'static> = GenerationalRef<Ref<'static, R>>;
type Mut<W: ?Sized + 'static> = GenerationalRefMut<RefMut<'static, W>>;
fn try_read(
&'static self,
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
created_at: &'static std::panic::Location<'static>,
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
at: crate::GenerationalRefBorrowInfo,
) -> Result<Self::Ref<T>, error::BorrowError> {
@@ -39,7 +33,7 @@ impl<T: 'static> Storage<T> for UnsyncStorage {
.map_err(|_| {
error::BorrowError::Dropped(error::ValueDroppedError {
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
created_at,
created_at: at.created_at,
})
})
.map(|guard| {
@@ -54,8 +48,6 @@ impl<T: 'static> Storage<T> for UnsyncStorage {
fn try_write(
&'static self,
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
created_at: &'static std::panic::Location<'static>,
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
at: crate::GenerationalRefMutBorrowInfo,
) -> Result<Self::Mut<T>, error::BorrowMutError> {
let borrow = self.0.try_borrow_mut();
@@ -71,7 +63,7 @@ impl<T: 'static> Storage<T> for UnsyncStorage {
.map_err(|_| {
error::BorrowMutError::Dropped(error::ValueDroppedError {
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
created_at,
created_at: at.created_at,
})
})
.map(|guard| {
@@ -121,6 +113,7 @@ impl<T: 'static> Storage<T> for UnsyncStorage {
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
borrow: GenerationalRefMutBorrowInfo {
borrowed_from: borrow.borrowed_from,
created_at: borrow.created_at,
},
})
}