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
use std::marker::PhantomData;

use core::Message;
use types::ProtobufType;

/// Optional ext field
pub struct ExtFieldOptional<M : Message, T : ProtobufType> {
    pub field_number: u32,
    pub phantom: PhantomData<(M, T)>,
}

/// Repeated ext field
pub struct ExtFieldRepeated<M : Message, T : ProtobufType> {
    pub field_number: u32,
    pub phantom: PhantomData<(M, T)>,
}

impl<M : Message, T : ProtobufType> ExtFieldOptional<M, T> {
    pub fn get(&self, m: &M) -> Option<T::Value> {
        m.get_unknown_fields()
            .get(self.field_number)
            .and_then(T::get_from_unknown)
    }
}

impl<M : Message, T : ProtobufType> ExtFieldRepeated<M, T> {
    pub fn get(&self, _m: &M) -> Vec<T::Value> {
        unimplemented!()
    }
}