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
31
32
33
34
35
//! Reflection internals.

use std::marker;

use crate::reflect::types::ProtobufType;
use crate::reflect::ProtobufValue;
use crate::reflect::RuntimeTypeBox;
use crate::wire_format::WireType;

/// Dynamic version of [`ProtobufType`](crate::reflect::types::ProtobufType).
///
/// This is used internally.
pub trait ProtobufTypeDynamic: Send + Sync + 'static {
    /// Wire type for this type.
    fn wire_type(&self) -> WireType;

    /// Get runtime type for this protobuf type.
    fn runtime_type(&self) -> RuntimeTypeBox;
}

pub(crate) struct ProtobufTypeDynamicImpl<T: ProtobufType>(pub marker::PhantomData<T>);

impl<T> ProtobufTypeDynamic for ProtobufTypeDynamicImpl<T>
where
    T: ProtobufType,
    <T as ProtobufType>::ProtobufValue: ProtobufValue,
{
    fn wire_type(&self) -> WireType {
        T::WIRE_TYPE
    }

    fn runtime_type(&self) -> RuntimeTypeBox {
        <T::ProtobufValue as ProtobufValue>::runtime_type_box()
    }
}