1use std::marker::PhantomData;
11
12use crate::descriptor::field_descriptor_proto::Type;
13use crate::reflect::runtime_types::RuntimeTypeTrait;
14use crate::reflect::ProtobufValue;
15use crate::Message;
16
17pub struct ExtFieldOptional<M, T> {
21 field_number: u32,
23 field_type: Type,
25 phantom: PhantomData<(M, T)>,
27}
28
29pub struct ExtFieldRepeated<M, V> {
33 #[allow(dead_code)]
35 field_number: u32,
36 #[allow(dead_code)]
38 field_type: Type,
39 phantom: PhantomData<(M, V)>,
41}
42
43impl<M, V> ExtFieldOptional<M, V> {
44 pub const fn new(field_number: u32, field_type: Type) -> Self {
46 ExtFieldOptional {
47 field_number,
48 field_type,
49 phantom: PhantomData,
50 }
51 }
52}
53
54impl<M: Message, V: ProtobufValue> ExtFieldOptional<M, V> {
55 pub fn get(&self, m: &M) -> Option<V> {
59 m.unknown_fields()
60 .get(self.field_number)
61 .and_then(|u| V::RuntimeType::get_from_unknown(u, self.field_type))
62 }
63}
64
65impl<M, V> ExtFieldRepeated<M, V> {
66 pub const fn new(field_number: u32, field_type: Type) -> Self {
68 ExtFieldRepeated {
69 field_number,
70 field_type,
71 phantom: PhantomData,
72 }
73 }
74}
75
76impl<M: Message, V: ProtobufValue> ExtFieldRepeated<M, V> {
77 pub fn get(&self, _m: &M) -> Vec<V> {
79 unimplemented!("extension fields implementation in rust-protobuf is stopgap")
80 }
81}