1 //! Reflection internals. 2 3 use std::marker; 4 5 use crate::reflect::runtime_types::RuntimeTypeTrait; 6 use crate::reflect::types::ProtobufTypeTrait; 7 use crate::reflect::ProtobufValue; 8 use crate::reflect::RuntimeType; 9 use crate::wire_format::WireType; 10 11 /// Dynamic version of [`ProtobufType`](crate::reflect::types::ProtobufType). 12 /// 13 /// This is used internally. 14 pub trait ProtobufTypeDynamic: Send + Sync + 'static { 15 /// Wire type for this type. wire_type(&self) -> WireType16 fn wire_type(&self) -> WireType; 17 18 /// Get runtime type for this protobuf type. runtime_type(&self) -> RuntimeType19 fn runtime_type(&self) -> RuntimeType; 20 } 21 22 pub(crate) struct ProtobufTypeDynamicImpl<T: ProtobufTypeTrait>(pub marker::PhantomData<T>); 23 24 impl<T> ProtobufTypeDynamic for ProtobufTypeDynamicImpl<T> 25 where 26 T: ProtobufTypeTrait, 27 <T as ProtobufTypeTrait>::ProtobufValue: ProtobufValue, 28 { wire_type(&self) -> WireType29 fn wire_type(&self) -> WireType { 30 T::WIRE_TYPE 31 } 32 runtime_type(&self) -> RuntimeType33 fn runtime_type(&self) -> RuntimeType { 34 <T::ProtobufValue as ProtobufValue>::RuntimeType::runtime_type_box() 35 } 36 } 37