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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use core::borrow::Borrow;
use core::ops::Deref;
use canonical::Canon;
use crate::{AnnoIter, Compound, LinkAnnotation};
mod cardinality;
mod max_key;
mod unit;
pub use cardinality::{Cardinality, Nth};
pub use max_key::{GetMaxKey, Keyed, MaxKey};
pub trait Annotation<Leaf>: Default + Canon + Combine<Self> {
fn from_leaf(leaf: &Leaf) -> Self;
}
pub trait Combine<A> {
fn combine<C>(iter: AnnoIter<C, A>) -> Self
where
C: Compound<A>,
A: Annotation<C::Leaf> + Borrow<Self>;
}
#[derive(Debug)]
pub enum WrappedAnnotation<'a, C, A> {
Owned(A),
Link(LinkAnnotation<'a, C, A>),
}
impl<'a, C, A> Deref for WrappedAnnotation<'a, C, A> {
type Target = A;
fn deref(&self) -> &Self::Target {
match self {
WrappedAnnotation::Owned(ref a) => a,
WrappedAnnotation::Link(a) => a,
}
}
}