1use std::sync::Arc;
5
6pub struct Gc<T: ?Sized>(Arc<T>);
8
9impl<T> Gc<T> {
10 pub fn new(val: T) -> Self { Self(Arc::new(val)) }
11}
12
13impl<T: ?Sized> Clone for Gc<T> { fn clone(&self) -> Self { Self(Arc::clone(&self.0)) } }
14impl<T: ?Sized> std::ops::Deref for Gc<T> {
15 type Target = T;
16 fn deref(&self) -> &T { &self.0 }
17}
18impl<T: std::fmt::Debug + ?Sized> std::fmt::Debug for Gc<T> {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 write!(f, "Gc({:?})", &*self.0)
21 }
22}