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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use std::any::Any;
use std::fmt;
#[cfg(feature = "bytes")]
use crate::bytes::Bytes;
#[cfg(feature = "bytes")]
use crate::chars::Chars;
use crate::reflect::runtime_types::RuntimeType;
use crate::reflect::runtime_types::RuntimeTypeBool;
#[cfg(feature = "bytes")]
use crate::reflect::runtime_types::RuntimeTypeCarllercheBytes;
#[cfg(feature = "bytes")]
use crate::reflect::runtime_types::RuntimeTypeCarllercheChars;
use crate::reflect::runtime_types::RuntimeTypeF32;
use crate::reflect::runtime_types::RuntimeTypeF64;
use crate::reflect::runtime_types::RuntimeTypeI32;
use crate::reflect::runtime_types::RuntimeTypeI64;
use crate::reflect::runtime_types::RuntimeTypeString;
use crate::reflect::runtime_types::RuntimeTypeU32;
use crate::reflect::runtime_types::RuntimeTypeU64;
use crate::reflect::runtime_types::RuntimeTypeVecU8;
use crate::reflect::value::value_box::ReflectValueBox;
use crate::reflect::value::value_ref::ReflectValueMut;
use crate::reflect::value::value_ref::ReflectValueRef;
use crate::reflect::RuntimeTypeBox;
pub(crate) mod value_box;
pub(crate) mod value_ref;
pub trait ProtobufValue:
Any + Clone + Default + fmt::Debug + Send + Sync + Sized + 'static
{
type RuntimeType: RuntimeType<Value = Self>;
fn runtime_type_box() -> RuntimeTypeBox {
Self::RuntimeType::runtime_type_box()
}
fn as_ref(value: &Self) -> ReflectValueRef {
Self::RuntimeType::as_ref(value)
}
fn as_mut(value: &mut Self) -> ReflectValueMut {
Self::RuntimeType::as_mut(value)
}
fn from_value_box(value_box: ReflectValueBox) -> Result<Self, ReflectValueBox> {
Self::RuntimeType::from_value_box(value_box)
}
fn set_from_value_box(target: &mut Self, value_box: ReflectValueBox) {
Self::RuntimeType::set_from_value_box(target, value_box)
}
fn default_value_ref() -> ReflectValueRef<'static> {
Self::RuntimeType::default_value_ref()
}
fn into_static_value_ref(value: Self) -> ReflectValueRef<'static> {
Self::RuntimeType::into_static_value_ref(value)
}
fn is_non_zero(value: &Self) -> bool {
Self::RuntimeType::is_non_zero(value)
}
}
impl ProtobufValue for u32 {
type RuntimeType = RuntimeTypeU32;
}
impl ProtobufValue for u64 {
type RuntimeType = RuntimeTypeU64;
}
impl ProtobufValue for i32 {
type RuntimeType = RuntimeTypeI32;
}
impl ProtobufValue for i64 {
type RuntimeType = RuntimeTypeI64;
}
impl ProtobufValue for f32 {
type RuntimeType = RuntimeTypeF32;
}
impl ProtobufValue for f64 {
type RuntimeType = RuntimeTypeF64;
}
impl ProtobufValue for bool {
type RuntimeType = RuntimeTypeBool;
}
impl ProtobufValue for String {
type RuntimeType = RuntimeTypeString;
}
impl ProtobufValue for Vec<u8> {
type RuntimeType = RuntimeTypeVecU8;
}
#[cfg(feature = "bytes")]
impl ProtobufValue for Bytes {
type RuntimeType = RuntimeTypeCarllercheBytes;
}
#[cfg(feature = "bytes")]
impl ProtobufValue for Chars {
type RuntimeType = RuntimeTypeCarllercheChars;
}