cell_gc/
gcleaf.rs

1use std;
2
3/// GCLeaf can be used to embed just about anything in a GC heap type.
4#[derive(Copy, Clone, Debug, PartialEq)]
5pub struct GCLeaf<T: Clone + 'static> {
6    // This private field has an underscore in the hopes that it is
7    // less likely to collide with useful features of T.
8    value_: T,
9}
10
11impl<T: Clone + 'static> GCLeaf<T> {
12    /// Create a new GCLeaf wrapping a given value.
13    pub fn new(value: T) -> GCLeaf<T> {
14        GCLeaf { value_: value }
15    }
16}
17
18impl<T: Clone + 'static> std::ops::Deref for GCLeaf<T> {
19    type Target = T;
20    fn deref(&self) -> &T {
21        &self.value_
22    }
23}
24
25impl<T: Clone + 'static> std::ops::DerefMut for GCLeaf<T> {
26    fn deref_mut(&mut self) -> &mut T {
27        &mut self.value_
28    }
29}