Coverage Report

Created: 2025-09-04 06:37

/rust/registry/src/index.crates.io-6f17d22bba15001f/protobuf-3.2.0/src/misc.rs
Line
Count
Source (jump to first uncovered line)
1
use std::mem;
2
use std::mem::MaybeUninit;
3
4
use crate::well_known_types;
5
6
/// `MaybeUninit::write_slice` is not stable.
7
0
pub(crate) fn maybe_uninit_write_slice<'a, T>(
8
0
    this: &'a mut [MaybeUninit<T>],
9
0
    src: &[T],
10
0
) -> &'a mut [T]
11
0
where
12
0
    T: Copy,
13
0
{
14
0
    // SAFETY: copy-paste from rust stdlib.
15
0
16
0
    let uninit_src: &[MaybeUninit<T>] = unsafe { mem::transmute(src) };
17
0
18
0
    this.copy_from_slice(uninit_src);
19
0
20
0
    unsafe { &mut *(this as *mut [MaybeUninit<T>] as *mut [T]) }
21
0
}
22
23
/// `MaybeUninit::array_assume_init` is not stable.
24
#[inline]
25
0
pub(crate) unsafe fn maybe_ununit_array_assume_init<T, const N: usize>(
26
0
    array: [MaybeUninit<T>; N],
27
0
) -> [T; N] {
28
0
    // SAFETY:
29
0
    // * The caller guarantees that all elements of the array are initialized
30
0
    // * `MaybeUninit<T>` and T are guaranteed to have the same layout
31
0
    // * `MaybeUninit` does not drop, so there are no double-frees
32
0
    // And thus the conversion is safe
33
0
    (&array as *const _ as *const [T; N]).read()
34
0
}
Unexecuted instantiation: protobuf::misc::maybe_ununit_array_assume_init::<u8, 4>
Unexecuted instantiation: protobuf::misc::maybe_ununit_array_assume_init::<u8, 8>
35
36
// bool <-> BoolValue
37
38
impl From<well_known_types::wrappers::BoolValue> for bool {
39
0
    fn from(inner: well_known_types::wrappers::BoolValue) -> Self {
40
0
        inner.value
41
0
    }
42
}
43
44
impl From<bool> for well_known_types::wrappers::BoolValue {
45
0
    fn from(inner: bool) -> Self {
46
0
        let mut value = Self::new();
47
0
        value.value = inner;
48
0
        value
49
0
    }
50
}
51
52
// Vec<u8> <-> BytesValue
53
54
impl From<well_known_types::wrappers::BytesValue> for Vec<u8> {
55
0
    fn from(inner: well_known_types::wrappers::BytesValue) -> Self {
56
0
        inner.value
57
0
    }
58
}
59
60
impl From<Vec<u8>> for well_known_types::wrappers::BytesValue {
61
0
    fn from(inner: Vec<u8>) -> Self {
62
0
        let mut value = Self::new();
63
0
        value.value = inner;
64
0
        value
65
0
    }
66
}
67
68
// f64 <-> DoubleValue
69
70
impl From<well_known_types::wrappers::DoubleValue> for f64 {
71
0
    fn from(inner: well_known_types::wrappers::DoubleValue) -> Self {
72
0
        inner.value
73
0
    }
74
}
75
76
impl From<f64> for well_known_types::wrappers::DoubleValue {
77
0
    fn from(inner: f64) -> Self {
78
0
        let mut value = Self::new();
79
0
        value.value = inner;
80
0
        value
81
0
    }
82
}
83
84
// f32 <-> FloatValue
85
86
impl From<well_known_types::wrappers::FloatValue> for f32 {
87
0
    fn from(inner: well_known_types::wrappers::FloatValue) -> Self {
88
0
        inner.value
89
0
    }
90
}
91
92
impl From<f32> for well_known_types::wrappers::FloatValue {
93
0
    fn from(inner: f32) -> Self {
94
0
        let mut value = Self::new();
95
0
        value.value = inner;
96
0
        value
97
0
    }
98
}
99
100
// i32 <-> Int32Value
101
102
impl From<well_known_types::wrappers::Int32Value> for i32 {
103
0
    fn from(inner: well_known_types::wrappers::Int32Value) -> Self {
104
0
        inner.value
105
0
    }
106
}
107
108
impl From<i32> for well_known_types::wrappers::Int32Value {
109
0
    fn from(inner: i32) -> Self {
110
0
        let mut value = Self::new();
111
0
        value.value = inner;
112
0
        value
113
0
    }
114
}
115
116
// i64 <-> Int64Value
117
118
impl From<well_known_types::wrappers::Int64Value> for i64 {
119
0
    fn from(inner: well_known_types::wrappers::Int64Value) -> Self {
120
0
        inner.value
121
0
    }
122
}
123
124
impl From<i64> for well_known_types::wrappers::Int64Value {
125
0
    fn from(inner: i64) -> Self {
126
0
        let mut value = Self::new();
127
0
        value.value = inner;
128
0
        value
129
0
    }
130
}
131
132
// u32 <-> UInt32Value
133
134
impl From<well_known_types::wrappers::UInt32Value> for u32 {
135
0
    fn from(inner: well_known_types::wrappers::UInt32Value) -> Self {
136
0
        inner.value
137
0
    }
138
}
139
140
impl From<u32> for well_known_types::wrappers::UInt32Value {
141
0
    fn from(inner: u32) -> Self {
142
0
        let mut value = Self::new();
143
0
        value.value = inner;
144
0
        value
145
0
    }
146
}
147
148
// u64 <-> UInt64Value
149
150
impl From<well_known_types::wrappers::UInt64Value> for u64 {
151
0
    fn from(inner: well_known_types::wrappers::UInt64Value) -> Self {
152
0
        inner.value
153
0
    }
154
}
155
156
impl From<u64> for well_known_types::wrappers::UInt64Value {
157
0
    fn from(inner: u64) -> Self {
158
0
        let mut value = Self::new();
159
0
        value.value = inner;
160
0
        value
161
0
    }
162
}
163
164
// () <-> Empty
165
166
impl From<well_known_types::empty::Empty> for () {
167
0
    fn from(_inner: well_known_types::empty::Empty) -> Self {}
168
}
169
170
impl From<()> for well_known_types::empty::Empty {
171
0
    fn from(_inner: ()) -> Self {
172
0
        Self::new()
173
0
    }
174
}