protobuf/reflect/
type_dynamic.rs

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