Skip to content

Commit 4acd75f

Browse files
committed
refcell-support
1 parent 7983619 commit 4acd75f

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

savefile/src/lib.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,22 +3010,42 @@ impl<'a, T: Introspect> IntrospectItem<'a> for IntrospectItemRwLock<'a, T> {
30103010
}
30113011
}
30123012

3013+
impl<'a,T:Introspect> Introspect for std::cell::Ref<'a,T> {
3014+
fn introspect_value(&self) -> String {
3015+
"Ref".to_string()
3016+
}
3017+
fn introspect_child(&self, index: usize) -> Option<Box<dyn IntrospectItem + '_>> {
3018+
(**self).introspect_child(index)
3019+
}
3020+
}
3021+
3022+
impl<'a,T:Introspect> IntrospectItem<'a> for std::cell::Ref<'a,T> {
3023+
fn key(&self) -> &str {
3024+
"ref"
3025+
}
3026+
/// The introspectable value of the child.
3027+
fn val(&self) -> &dyn Introspect {
3028+
&*self
3029+
}
3030+
}
3031+
30133032
impl<T: Introspect> Introspect for RefCell<T> {
30143033
fn introspect_value(&self) -> String {
3015-
format!(
3016-
"RefCell({} (deep introspect not supported))",
3017-
self.borrow().introspect_value()
3018-
)
3034+
"RefCell".to_string()
30193035
}
30203036

3021-
fn introspect_child(&self, _index: usize) -> Option<Box<dyn IntrospectItem + '_>> {
3037+
fn introspect_child(&self, index: usize) -> Option<Box<dyn IntrospectItem + '_>> {
30223038
// Introspect not supported
3023-
None
3039+
if index != 0 {
3040+
return None;
3041+
}
3042+
let rf = self.borrow();
3043+
Some(Box::new(rf))
30243044
}
30253045

30263046
fn introspect_len(&self) -> usize {
30273047
// Introspect not supported
3028-
0
3048+
1
30293049
}
30303050
}
30313051

0 commit comments

Comments
 (0)