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
/*
pub trait Descriptor {
    type Description;
    type Described;

    fn create(&self) -> Self::Described;
    fn describe<'a>(&'a self) -> &'a Self::Description;
}
*/

pub trait CodecList: Sized {
    type D: ?Sized;

    fn new() -> Self;

    // TODO more lookup functions
    fn by_name(&self, name: &str) -> Option<&'static Self::D>;

    fn append(&mut self, desc: &'static Self::D);

    fn from_list(descs: &[&'static Self::D]) -> Self {
        let mut c = Self::new();
        for &desc in descs {
            c.append(desc);
        }

        c
    }
}