Coverage Report

Created: 2025-02-25 06:39

/rust/registry/src/index.crates.io-6f17d22bba15001f/protobuf-2.28.0/src/reflect/value.rs
Line
Count
Source (jump to first uncovered line)
1
use std::any::Any;
2
3
#[cfg(feature = "bytes")]
4
use bytes::Bytes;
5
6
use super::*;
7
#[cfg(feature = "bytes")]
8
use crate::chars::Chars;
9
10
/// Type implemented by all protobuf elementary types
11
/// (ints, floats, bool, string, bytes, enums, messages).
12
pub trait ProtobufValue: Any + 'static {
13
    /// As ref
14
    fn as_ref(&self) -> ReflectValueRef;
15
16
    /// Convert to `Any`
17
0
    fn as_any(&self) -> &dyn Any {
18
0
        unimplemented!()
Unexecuted instantiation: <alloc::vec::Vec<u8> as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::plugin::CodeGeneratorResponse_File as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::plugin::Version as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::source_context::SourceContext as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::any::Any as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Field_Kind as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Field_Cardinality as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Field as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Option as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Syntax as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::type_pb::EnumValue as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <alloc::string::String as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <bool as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <f64 as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <f32 as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <i32 as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <u32 as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <i64 as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <u64 as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::api::Mixin as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::api::Method as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::well_known_types::struct_pb::Value as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::EnumOptions as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::FileOptions as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::FieldOptions as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::OneofOptions as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::MethodOptions as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::MessageOptions as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::ServiceOptions as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::SourceCodeInfo as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::DescriptorProto as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::EnumValueOptions as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::GeneratedCodeInfo as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::FieldOptions_CType as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::EnumDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::FieldOptions_JSType as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::FileDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::UninterpretedOption as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::FieldDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::OneofDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::ExtensionRangeOptions as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::MethodDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::ServiceDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::SourceCodeInfo_Location as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::EnumValueDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::FileOptions_OptimizeMode as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::FieldDescriptorProto_Type as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::FieldDescriptorProto_Label as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::GeneratedCodeInfo_Annotation as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::UninterpretedOption_NamePart as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::DescriptorProto_ReservedRange as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::DescriptorProto_ExtensionRange as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::MethodOptions_IdempotencyLevel as protobuf::reflect::value::ProtobufValue>::as_any
Unexecuted instantiation: <protobuf::descriptor::EnumDescriptorProto_EnumReservedRange as protobuf::reflect::value::ProtobufValue>::as_any
19
    }
20
21
    /// Is value non-zero?
22
0
    fn is_non_zero(&self) -> bool {
23
0
        self.as_ref().is_non_zero()
24
0
    }
Unexecuted instantiation: <alloc::vec::Vec<u8> as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::plugin::CodeGeneratorResponse_File as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::plugin::Version as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::source_context::SourceContext as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::any::Any as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Field_Kind as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Field_Cardinality as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Field as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Option as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Syntax as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::type_pb::EnumValue as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <alloc::string::String as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <bool as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <f64 as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <f32 as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <i32 as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <u32 as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <i64 as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <u64 as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::api::Mixin as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::api::Method as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::well_known_types::struct_pb::Value as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::EnumOptions as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::FileOptions as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::FieldOptions as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::OneofOptions as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::MethodOptions as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::MessageOptions as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::ServiceOptions as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::SourceCodeInfo as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::DescriptorProto as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::EnumValueOptions as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::GeneratedCodeInfo as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::FieldOptions_CType as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::EnumDescriptorProto as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::FieldOptions_JSType as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::FileDescriptorProto as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::UninterpretedOption as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::FieldDescriptorProto as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::OneofDescriptorProto as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::ExtensionRangeOptions as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::MethodDescriptorProto as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::ServiceDescriptorProto as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::SourceCodeInfo_Location as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::EnumValueDescriptorProto as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::FileOptions_OptimizeMode as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::FieldDescriptorProto_Type as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::FieldDescriptorProto_Label as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::GeneratedCodeInfo_Annotation as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::UninterpretedOption_NamePart as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::DescriptorProto_ReservedRange as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::DescriptorProto_ExtensionRange as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::MethodOptions_IdempotencyLevel as protobuf::reflect::value::ProtobufValue>::is_non_zero
Unexecuted instantiation: <protobuf::descriptor::EnumDescriptorProto_EnumReservedRange as protobuf::reflect::value::ProtobufValue>::is_non_zero
25
26
    /// Return `ProtobufValueRef` if self is `Copy`.
27
    ///
28
    /// # Panics
29
    ///
30
    /// if `Self` is not `Copy`.
31
0
    fn as_ref_copy(&self) -> ReflectValueRef<'static>
32
0
//where Self : Copy // TODO
33
0
    {
34
0
        match self.as_ref() {
35
0
            ReflectValueRef::Bool(v) => ReflectValueRef::Bool(v),
36
0
            ReflectValueRef::U32(v) => ReflectValueRef::U32(v),
37
0
            ReflectValueRef::U64(v) => ReflectValueRef::U64(v),
38
0
            ReflectValueRef::I32(v) => ReflectValueRef::I32(v),
39
0
            ReflectValueRef::I64(v) => ReflectValueRef::I64(v),
40
0
            ReflectValueRef::F32(v) => ReflectValueRef::F32(v),
41
0
            ReflectValueRef::F64(v) => ReflectValueRef::F64(v),
42
0
            ReflectValueRef::Enum(v) => ReflectValueRef::Enum(v),
43
            ReflectValueRef::String(..)
44
            | ReflectValueRef::Bytes(..)
45
0
            | ReflectValueRef::Message(..) => unreachable!(),
46
        }
47
0
    }
Unexecuted instantiation: <alloc::vec::Vec<u8> as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::plugin::CodeGeneratorResponse_File as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::plugin::Version as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::source_context::SourceContext as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::any::Any as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Field_Kind as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Field_Cardinality as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Field as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Option as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::type_pb::Syntax as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::type_pb::EnumValue as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <alloc::string::String as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <bool as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <f64 as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <f32 as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <i32 as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <u32 as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <i64 as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <u64 as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::api::Mixin as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::api::Method as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::well_known_types::struct_pb::Value as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::EnumOptions as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::FileOptions as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::FieldOptions as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::OneofOptions as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::MethodOptions as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::MessageOptions as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::ServiceOptions as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::SourceCodeInfo as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::DescriptorProto as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::EnumValueOptions as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::GeneratedCodeInfo as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::FieldOptions_CType as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::EnumDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::FieldOptions_JSType as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::FileDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::UninterpretedOption as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::FieldDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::OneofDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::ExtensionRangeOptions as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::MethodDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::ServiceDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::SourceCodeInfo_Location as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::EnumValueDescriptorProto as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::FileOptions_OptimizeMode as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::FieldDescriptorProto_Type as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::FieldDescriptorProto_Label as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::GeneratedCodeInfo_Annotation as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::UninterpretedOption_NamePart as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::DescriptorProto_ReservedRange as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::DescriptorProto_ExtensionRange as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::MethodOptions_IdempotencyLevel as protobuf::reflect::value::ProtobufValue>::as_ref_copy
Unexecuted instantiation: <protobuf::descriptor::EnumDescriptorProto_EnumReservedRange as protobuf::reflect::value::ProtobufValue>::as_ref_copy
48
}
49
50
impl ProtobufValue for u32 {
51
0
    fn as_ref(&self) -> ReflectValueRef {
52
0
        ReflectValueRef::U32(*self)
53
0
    }
54
}
55
56
impl ProtobufValue for u64 {
57
0
    fn as_ref(&self) -> ReflectValueRef {
58
0
        ReflectValueRef::U64(*self)
59
0
    }
60
}
61
62
impl ProtobufValue for i32 {
63
0
    fn as_ref(&self) -> ReflectValueRef {
64
0
        ReflectValueRef::I32(*self)
65
0
    }
66
}
67
68
impl ProtobufValue for i64 {
69
0
    fn as_ref(&self) -> ReflectValueRef {
70
0
        ReflectValueRef::I64(*self)
71
0
    }
72
}
73
74
impl ProtobufValue for f32 {
75
0
    fn as_ref(&self) -> ReflectValueRef {
76
0
        ReflectValueRef::F32(*self)
77
0
    }
78
}
79
80
impl ProtobufValue for f64 {
81
0
    fn as_ref(&self) -> ReflectValueRef {
82
0
        ReflectValueRef::F64(*self)
83
0
    }
84
}
85
86
impl ProtobufValue for bool {
87
0
    fn as_ref(&self) -> ReflectValueRef {
88
0
        ReflectValueRef::Bool(*self)
89
0
    }
90
}
91
92
impl ProtobufValue for String {
93
0
    fn as_ref(&self) -> ReflectValueRef {
94
0
        ReflectValueRef::String(*&self)
95
0
    }
96
}
97
98
impl ProtobufValue for str {
99
0
    fn as_ref(&self) -> ReflectValueRef {
100
0
        ReflectValueRef::String(self)
101
0
    }
102
}
103
104
impl ProtobufValue for Vec<u8> {
105
0
    fn as_ref(&self) -> ReflectValueRef {
106
0
        ReflectValueRef::Bytes(*&self)
107
0
    }
108
}
109
110
#[cfg(feature = "bytes")]
111
impl ProtobufValue for Bytes {
112
    fn as_ref(&self) -> ReflectValueRef {
113
        ReflectValueRef::Bytes(&*self)
114
    }
115
}
116
117
#[cfg(feature = "bytes")]
118
impl ProtobufValue for Chars {
119
    fn as_ref(&self) -> ReflectValueRef {
120
        ReflectValueRef::String(&*self)
121
    }
122
}
123
124
// conflicting implementations, so generated code is used instead
125
/*
126
impl<E : ProtobufEnum> ProtobufValue for E {
127
    fn as_ref(&self) -> ProtobufValueRef {
128
        ProtobufValueRef::Enum(self.descriptor())
129
    }
130
}
131
132
impl<M : Message> ProtobufValue for M {
133
    fn as_ref(&self) -> ProtobufValueRef {
134
        ProtobufValueRef::Message(self)
135
    }
136
}
137
*/
138
139
/// A reference to a value
140
#[derive(Debug)]
141
pub enum ReflectValueRef<'a> {
142
    /// `u32`
143
    U32(u32),
144
    /// `u64`
145
    U64(u64),
146
    /// `i32`
147
    I32(i32),
148
    /// `i64`
149
    I64(i64),
150
    /// `f32`
151
    F32(f32),
152
    /// `f64`
153
    F64(f64),
154
    /// `bool`
155
    Bool(bool),
156
    /// `string`
157
    String(&'a str),
158
    /// `bytes`
159
    Bytes(&'a [u8]),
160
    /// `enum`
161
    // TODO: change to (i32, EnumDescriptor)
162
    Enum(&'static EnumValueDescriptor),
163
    /// `message`
164
    Message(&'a dyn Message),
165
}
166
167
impl<'a> ReflectValueRef<'a> {
168
    /// Value is "non-zero"?
169
    #[doc(hidden)]
170
0
    pub fn is_non_zero(&self) -> bool {
171
0
        match *self {
172
0
            ReflectValueRef::U32(v) => v != 0,
173
0
            ReflectValueRef::U64(v) => v != 0,
174
0
            ReflectValueRef::I32(v) => v != 0,
175
0
            ReflectValueRef::I64(v) => v != 0,
176
0
            ReflectValueRef::F32(v) => v != 0.,
177
0
            ReflectValueRef::F64(v) => v != 0.,
178
0
            ReflectValueRef::Bool(v) => v,
179
0
            ReflectValueRef::String(v) => !v.is_empty(),
180
0
            ReflectValueRef::Bytes(v) => !v.is_empty(),
181
0
            ReflectValueRef::Enum(v) => v.value() != 0,
182
0
            ReflectValueRef::Message(_) => true,
183
        }
184
0
    }
185
}