indexical/
pointer.rs

1//! Abstraction over smart pointers.
2
3use std::marker::PhantomData;
4use std::ops::Deref;
5use std::rc::Rc;
6use std::sync::Arc;
7
8/// Abstraction over smart pointers.
9///
10/// Used so to make the indexical data structures generic with respect
11/// to choice of `Rc` or `Arc` (or your own clonable smart pointer!).
12pub trait PointerFamily<'a> {
13    /// Pointer type for a given family.
14    type Pointer<T: 'a>: Deref<Target = T> + Clone;
15}
16
17/// Family of [`Arc`] pointers.
18pub struct ArcFamily;
19
20impl<'a> PointerFamily<'a> for ArcFamily {
21    type Pointer<T: 'a> = Arc<T>;
22}
23
24/// Family of [`Rc`] pointers.
25pub struct RcFamily;
26
27impl<'a> PointerFamily<'a> for RcFamily {
28    type Pointer<T: 'a> = Rc<T>;
29}
30
31/// Family of `&`-references.
32pub struct RefFamily<'a>(PhantomData<&'a ()>);
33
34impl<'a> PointerFamily<'a> for RefFamily<'a> {
35    type Pointer<T: 'a> = &'a T;
36}