1 use std::fmt; 2 3 #[cfg(feature = "bytes")] 4 use ::bytes::Bytes; 5 6 #[cfg(feature = "bytes")] 7 use crate::chars::Chars; 8 use crate::reflect::runtime_types::RuntimeTypeBool; 9 use crate::reflect::runtime_types::RuntimeTypeF32; 10 use crate::reflect::runtime_types::RuntimeTypeF64; 11 use crate::reflect::runtime_types::RuntimeTypeI32; 12 use crate::reflect::runtime_types::RuntimeTypeI64; 13 use crate::reflect::runtime_types::RuntimeTypeString; 14 #[cfg(feature = "bytes")] 15 use crate::reflect::runtime_types::RuntimeTypeTokioBytes; 16 #[cfg(feature = "bytes")] 17 use crate::reflect::runtime_types::RuntimeTypeTokioChars; 18 use crate::reflect::runtime_types::RuntimeTypeTrait; 19 use crate::reflect::runtime_types::RuntimeTypeU32; 20 use crate::reflect::runtime_types::RuntimeTypeU64; 21 use crate::reflect::runtime_types::RuntimeTypeVecU8; 22 23 pub(crate) mod value_box; 24 pub(crate) mod value_ref; 25 26 /// Type implemented by all protobuf singular types 27 /// (primitives, string, messages, enums). 28 /// 29 /// Used in reflection. 30 pub trait ProtobufValue: Clone + Default + fmt::Debug + Send + Sync + Sized + 'static { 31 /// Actual implementation of type properties. 32 type RuntimeType: RuntimeTypeTrait<Value = Self>; 33 } 34 35 impl ProtobufValue for u32 { 36 type RuntimeType = RuntimeTypeU32; 37 } 38 39 impl ProtobufValue for u64 { 40 type RuntimeType = RuntimeTypeU64; 41 } 42 43 impl ProtobufValue for i32 { 44 type RuntimeType = RuntimeTypeI32; 45 } 46 47 impl ProtobufValue for i64 { 48 type RuntimeType = RuntimeTypeI64; 49 } 50 51 impl ProtobufValue for f32 { 52 type RuntimeType = RuntimeTypeF32; 53 } 54 55 impl ProtobufValue for f64 { 56 type RuntimeType = RuntimeTypeF64; 57 } 58 59 impl ProtobufValue for bool { 60 type RuntimeType = RuntimeTypeBool; 61 } 62 63 impl ProtobufValue for String { 64 type RuntimeType = RuntimeTypeString; 65 } 66 67 impl ProtobufValue for Vec<u8> { 68 type RuntimeType = RuntimeTypeVecU8; 69 } 70 71 #[cfg(feature = "bytes")] 72 impl ProtobufValue for Bytes { 73 type RuntimeType = RuntimeTypeTokioBytes; 74 } 75 76 #[cfg(feature = "bytes")] 77 impl ProtobufValue for Chars { 78 type RuntimeType = RuntimeTypeTokioChars; 79 } 80 81 // conflicting implementations, so generated code is used instead 82 /* 83 impl<E : ProtobufEnum> ProtobufValue for E { 84 } 85 86 impl<M : Message> ProtobufValue for M { 87 } 88 */ 89