indexical/
pointer.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Abstraction over smart pointers.

use std::marker::PhantomData;
use std::ops::Deref;
use std::rc::Rc;
use std::sync::Arc;

/// Abstraction over smart pointers.
///
/// Used so to make the indexical data structures generic with respect
/// to choice of `Rc` or `Arc` (or your own clonable smart pointer!).
pub trait PointerFamily<'a> {
    /// Pointer type for a given family.
    type Pointer<T: 'a>: Deref<Target = T> + Clone;
}

/// Family of [`Arc`] pointers.
pub struct ArcFamily;

impl<'a> PointerFamily<'a> for ArcFamily {
    type Pointer<T: 'a> = Arc<T>;
}

/// Family of [`Rc`] pointers.
pub struct RcFamily;

impl<'a> PointerFamily<'a> for RcFamily {
    type Pointer<T: 'a> = Rc<T>;
}

/// Family of `&`-references.
pub struct RefFamily<'a>(PhantomData<&'a ()>);

impl<'a> PointerFamily<'a> for RefFamily<'a> {
    type Pointer<T: 'a> = &'a T;
}