@@ -97,14 +97,18 @@ pub unsafe extern "C" fn ddog_array_queue_drop(queue_ptr: *mut ArrayQueue) {
97
97
#[ allow( unused) ]
98
98
#[ repr( C ) ]
99
99
pub enum ArrayQueuePushResult {
100
- Ok ( bool ) ,
100
+ Ok ,
101
+ Full ( * mut c_void ) ,
101
102
Err ( Error ) ,
102
103
}
103
104
104
- impl From < Result < ( ) , anyhow:: Error > > for ArrayQueuePushResult {
105
- fn from ( result : Result < ( ) , anyhow:: Error > ) -> Self {
105
+ impl From < Result < Result < ( ) , * mut c_void > , anyhow:: Error > > for ArrayQueuePushResult {
106
+ fn from ( result : Result < Result < ( ) , * mut c_void > , anyhow:: Error > ) -> Self {
106
107
match result {
107
- Ok ( _) => ArrayQueuePushResult :: Ok ( true ) ,
108
+ Ok ( value) => match value {
109
+ Ok ( ( ) ) => ArrayQueuePushResult :: Ok ,
110
+ Err ( value) => ArrayQueuePushResult :: Full ( value) ,
111
+ } ,
108
112
Err ( err) => ArrayQueuePushResult :: Err ( err. into ( ) ) ,
109
113
}
110
114
}
@@ -121,9 +125,7 @@ pub unsafe extern "C" fn ddog_array_queue_push(
121
125
) -> ArrayQueuePushResult {
122
126
( || {
123
127
let queue = ddog_array_queue_ptr_to_inner ( queue_ptr) ?;
124
- queue
125
- . push ( value)
126
- . map_err ( |_| anyhow:: anyhow!( "array_queue full" ) )
128
+ anyhow:: Ok ( queue. push ( value) )
127
129
} ) ( )
128
130
. context ( "array_queue_push failed" )
129
131
. into ( )
@@ -133,13 +135,17 @@ pub unsafe extern "C" fn ddog_array_queue_push(
133
135
#[ repr( C ) ]
134
136
pub enum ArrayQueuePopResult {
135
137
Ok ( * mut c_void ) ,
138
+ Empty ,
136
139
Err ( Error ) ,
137
140
}
138
141
139
- impl From < anyhow:: Result < * mut c_void > > for ArrayQueuePopResult {
140
- fn from ( result : anyhow:: Result < * mut c_void > ) -> Self {
142
+ impl From < anyhow:: Result < Option < * mut c_void > > > for ArrayQueuePopResult {
143
+ fn from ( result : anyhow:: Result < Option < * mut c_void > > ) -> Self {
141
144
match result {
142
- Ok ( value) => ArrayQueuePopResult :: Ok ( value) ,
145
+ Ok ( value) => match value {
146
+ Some ( value) => ArrayQueuePopResult :: Ok ( value) ,
147
+ None => ArrayQueuePopResult :: Empty ,
148
+ } ,
143
149
Err ( err) => ArrayQueuePopResult :: Err ( err. into ( ) ) ,
144
150
}
145
151
}
@@ -152,26 +158,24 @@ impl From<anyhow::Result<*mut c_void>> for ArrayQueuePopResult {
152
158
pub unsafe extern "C" fn ddog_array_queue_pop ( queue_ptr : * mut ArrayQueue ) -> ArrayQueuePopResult {
153
159
( || {
154
160
let queue = ddog_array_queue_ptr_to_inner ( queue_ptr) ?;
155
- queue
156
- . pop ( )
157
- . ok_or_else ( || anyhow:: anyhow!( "array_queue empty" ) )
161
+ anyhow:: Ok ( queue. pop ( ) )
158
162
} ) ( )
159
163
. context ( "array_queue_pop failed" )
160
164
. into ( )
161
165
}
162
166
163
167
#[ allow( unused) ]
164
168
#[ repr( C ) ]
165
- pub enum ArrayQueueIsEmptyResult {
169
+ pub enum ArrayQueueBoolResult {
166
170
Ok ( bool ) ,
167
171
Err ( Error ) ,
168
172
}
169
173
170
- impl From < anyhow:: Result < bool > > for ArrayQueueIsEmptyResult {
174
+ impl From < anyhow:: Result < bool > > for ArrayQueueBoolResult {
171
175
fn from ( result : anyhow:: Result < bool > ) -> Self {
172
176
match result {
173
- Ok ( value) => ArrayQueueIsEmptyResult :: Ok ( value) ,
174
- Err ( err) => ArrayQueueIsEmptyResult :: Err ( err. into ( ) ) ,
177
+ Ok ( value) => ArrayQueueBoolResult :: Ok ( value) ,
178
+ Err ( err) => ArrayQueueBoolResult :: Err ( err. into ( ) ) ,
175
179
}
176
180
}
177
181
}
@@ -182,7 +186,7 @@ impl From<anyhow::Result<bool>> for ArrayQueueIsEmptyResult {
182
186
#[ no_mangle]
183
187
pub unsafe extern "C" fn ddog_array_queue_is_empty (
184
188
queue_ptr : * mut ArrayQueue ,
185
- ) -> ArrayQueueIsEmptyResult {
189
+ ) -> ArrayQueueBoolResult {
186
190
( || {
187
191
let queue = ddog_array_queue_ptr_to_inner ( queue_ptr) ?;
188
192
anyhow:: Ok ( queue. is_empty ( ) )
@@ -193,16 +197,16 @@ pub unsafe extern "C" fn ddog_array_queue_is_empty(
193
197
194
198
#[ allow( unused) ]
195
199
#[ repr( C ) ]
196
- pub enum ArrayQueueLenResult {
200
+ pub enum ArrayQueueUsizeResult {
197
201
Ok ( usize ) ,
198
202
Err ( Error ) ,
199
203
}
200
204
201
- impl From < anyhow:: Result < usize > > for ArrayQueueLenResult {
205
+ impl From < anyhow:: Result < usize > > for ArrayQueueUsizeResult {
202
206
fn from ( result : anyhow:: Result < usize > ) -> Self {
203
207
match result {
204
- Ok ( value) => ArrayQueueLenResult :: Ok ( value) ,
205
- Err ( err) => ArrayQueueLenResult :: Err ( err. into ( ) ) ,
208
+ Ok ( value) => ArrayQueueUsizeResult :: Ok ( value) ,
209
+ Err ( err) => ArrayQueueUsizeResult :: Err ( err. into ( ) ) ,
206
210
}
207
211
}
208
212
}
@@ -211,7 +215,7 @@ impl From<anyhow::Result<usize>> for ArrayQueueLenResult {
211
215
/// # Safety
212
216
/// The pointer is null or points to a valid memory location allocated by array_queue_new.
213
217
#[ no_mangle]
214
- pub unsafe extern "C" fn ddog_array_queue_len ( queue_ptr : * mut ArrayQueue ) -> ArrayQueueLenResult {
218
+ pub unsafe extern "C" fn ddog_array_queue_len ( queue_ptr : * mut ArrayQueue ) -> ArrayQueueUsizeResult {
215
219
( || {
216
220
let queue = ddog_array_queue_ptr_to_inner ( queue_ptr) ?;
217
221
anyhow:: Ok ( queue. len ( ) )
0 commit comments