librashader-capi 0.11.3

RetroArch shaders for all.
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
//! librashader error C API. (`libra_error_*`).
use std::any::Any;
use std::ffi::{c_char, CString};
use std::mem::MaybeUninit;
use std::ptr::NonNull;
use thiserror::Error;

/// The error type for librashader C API.
#[non_exhaustive]
#[derive(Error, Debug)]
pub enum LibrashaderError {
    /// An unknown error or panic occurred.
    #[error("There was an unknown error.")]
    UnknownError(Box<dyn Any + Send + 'static>),

    /// An invalid parameter (likely null), was passed.
    #[error("The parameter was null or invalid.")]
    InvalidParameter(&'static str),

    /// The string provided was not valid UTF-8.
    #[error("The provided string was not valid UTF8.")]
    InvalidString(#[from] std::str::Utf8Error),

    /// An error occurred in the preset parser.
    #[error("There was an error parsing the preset.")]
    PresetError(#[from] librashader::presets::ParsePresetError),

    /// An error occurred in the shader preprocessor.
    #[error("There was an error preprocessing the shader source.")]
    PreprocessError(#[from] librashader::preprocess::PreprocessError),

    /// An error occurred in the shader compiler.
    #[error("There was an error compiling the shader source.")]
    ShaderCompileError(#[from] librashader::reflect::ShaderCompileError),

    /// An error occrred when validating and reflecting the shader.
    #[error("There was an error reflecting the shader source.")]
    ShaderReflectError(#[from] librashader::reflect::ShaderReflectError),

    /// An invalid shader parameter name was provided.
    #[error("The provided parameter name was invalid.")]
    UnknownShaderParameter(*const c_char),

    /// An error occurred with the OpenGL filter chain.
    #[cfg(feature = "runtime-opengl")]
    #[cfg_attr(feature = "docsrs", doc(cfg(feature = "runtime-opengl")))]
    #[error("There was an error in the OpenGL filter chain.")]
    OpenGlFilterError(#[from] librashader::runtime::gl::error::FilterChainError),

    /// An error occurred with the Direct3D 11 filter chain.
    #[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
    #[cfg_attr(
        feature = "docsrs",
        doc(cfg(all(target_os = "windows", feature = "runtime-d3d11")))
    )]
    #[error("There was an error in the D3D11 filter chain.")]
    D3D11FilterError(#[from] librashader::runtime::d3d11::error::FilterChainError),

    /// An error occurred with the Direct3D 12 filter chain.
    #[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
    #[cfg_attr(
        feature = "docsrs",
        doc(cfg(all(target_os = "windows", feature = "runtime-d3d12")))
    )]
    #[error("There was an error in the D3D12 filter chain.")]
    D3D12FilterError(#[from] librashader::runtime::d3d12::error::FilterChainError),

    /// An error occurred with the Direct3D 9 filter chain.
    #[cfg(all(target_os = "windows", feature = "runtime-d3d9"))]
    #[cfg_attr(
        feature = "docsrs",
        doc(cfg(all(target_os = "windows", feature = "runtime-d3d9")))
    )]
    #[error("There was an error in the D3D9 filter chain.")]
    D3D9FilterError(#[from] librashader::runtime::d3d9::error::FilterChainError),

    /// An error occurred with the Vulkan filter chain.

    #[cfg(feature = "runtime-vulkan")]
    #[cfg_attr(feature = "docsrs", doc(cfg(feature = "runtime-vulkan")))]
    #[error("There was an error in the Vulkan filter chain.")]
    VulkanFilterError(#[from] librashader::runtime::vk::error::FilterChainError),

    /// An error occurred with the Metal filter chain.
    #[cfg_attr(
        feature = "docsrs",
        doc(cfg(all(target_vendor = "apple", feature = "runtime-metal")))
    )]
    #[cfg(all(target_vendor = "apple", feature = "runtime-metal"))]
    #[error("There was an error in the Metal filter chain.")]
    MetalFilterError(#[from] librashader::runtime::mtl::error::FilterChainError),
    /// This error is unreachable.
    #[error("This error is not reachable")]
    Infallible(#[from] std::convert::Infallible),
}

/// Error codes for librashader error types.
#[repr(i32)]
pub enum LIBRA_ERRNO {
    /// Error code for an unknown error.
    UNKNOWN_ERROR = 0,

    /// Error code for an invalid parameter.
    INVALID_PARAMETER = 1,

    /// Error code for an invalid (non-UTF8) string.
    INVALID_STRING = 2,

    /// Error code for a preset parser error.
    PRESET_ERROR = 3,

    /// Error code for a preprocessor error.
    PREPROCESS_ERROR = 4,

    /// Error code for a shader parameter error.
    SHADER_PARAMETER_ERROR = 5,

    /// Error code for a reflection error.
    REFLECT_ERROR = 6,

    /// Error code for a runtime error.
    RUNTIME_ERROR = 7,

    /// Error code for when a LUT fails to load at runtime.
    LUT_LOAD_ERROR = 8,

    /// Error code when a shader fails to be compiled by the graphics driver.
    COMPILE_ERROR = 9,
}

// Nothing here can use extern_fn because they are lower level than libra_error_t.

/// Function pointer definition for libra_error_errno
pub type PFN_libra_error_errno = extern "C" fn(error: libra_error_t) -> LIBRA_ERRNO;
#[no_mangle]
/// Get the error code corresponding to this error object.
///
/// ## Safety
///   - `error` must be valid and initialized.
pub unsafe extern "C" fn libra_error_errno(error: libra_error_t) -> LIBRA_ERRNO {
    let Some(error) = error else {
        return LIBRA_ERRNO::UNKNOWN_ERROR;
    };

    unsafe {
        let code = error.as_ref().get_code();

        // Unwrap inner runtime codes if the parsing was done in the
        // runtime crate
        if matches!(code, LIBRA_ERRNO::RUNTIME_ERROR) {
            error.as_ref().get_runtime_code()
        } else {
            code
        }
    }
}

/// Function pointer definition for libra_error_print
pub type PFN_libra_error_print = extern "C" fn(error: libra_error_t) -> i32;
#[no_mangle]
/// Print the error message.
///
/// If `error` is null, this function does nothing and returns 1. Otherwise, this function returns 0.
/// ## Safety
///   - `error` must be a valid and initialized instance of `libra_error_t`.
pub unsafe extern "C" fn libra_error_print(error: libra_error_t) -> i32 {
    let Some(error) = error else { return 1 };
    unsafe {
        let error = error.as_ref();
        println!("{error:?}: {error}");
    }
    0
}

/// Function pointer definition for libra_error_free
pub type PFN_libra_error_free = extern "C" fn(error: *mut libra_error_t) -> i32;
#[no_mangle]
/// Frees any internal state kept by the error.
///
/// If `error` is null, this function does nothing and returns 1. Otherwise, this function returns 0.
/// The resulting error object becomes null.
/// ## Safety
///   - `error` must be null or a pointer to a valid and initialized instance of `libra_error_t`.
pub unsafe extern "C" fn libra_error_free(error: *mut libra_error_t) -> i32 {
    if error.is_null() {
        return 1;
    }

    let error = unsafe { &mut *error };
    let error = error.take();
    let Some(error) = error else {
        return 1;
    };

    unsafe { drop(Box::from_raw(error.as_ptr())) }
    0
}

/// Function pointer definition for libra_error_write
pub type PFN_libra_error_write =
    extern "C" fn(error: libra_error_t, out: *mut MaybeUninit<*mut c_char>) -> i32;
#[no_mangle]
/// Writes the error message into `out`
///
/// If `error` is null, this function does nothing and returns 1. Otherwise, this function returns 0.
/// ## Safety
///   - `error` must be a valid and initialized instance of `libra_error_t`.
///   - `out` must be a non-null pointer. The resulting string must not be modified.
pub unsafe extern "C" fn libra_error_write(
    error: libra_error_t,
    out: *mut MaybeUninit<*mut c_char>,
) -> i32 {
    let Some(error) = error else { return 1 };
    if out.is_null() {
        return 1;
    }

    unsafe {
        let error = error.as_ref();
        let Ok(cstring) = CString::new(format!("{error:?}: {error}")) else {
            return 1;
        };

        out.write(MaybeUninit::new(cstring.into_raw()))
    }
    0
}

/// Function pointer definition for libra_error_free_string
pub type PFN_libra_error_free_string = extern "C" fn(out: *mut *mut c_char) -> i32;
#[no_mangle]
/// Frees an error string previously allocated by `libra_error_write`.
///
/// After freeing, the pointer will be set to null.
/// ## Safety
///   - If `libra_error_write` is not null, it must point to a string previously returned by `libra_error_write`.
///     Attempting to free anything else, including strings or objects from other librashader functions, is immediate
///     Undefined Behaviour.
pub unsafe extern "C" fn libra_error_free_string(out: *mut *mut c_char) -> i32 {
    if out.is_null() {
        return 1;
    }

    unsafe {
        let ptr = out.read();
        *out = std::ptr::null_mut();
        drop(CString::from_raw(ptr))
    }
    0
}

impl LibrashaderError {
    pub(crate) const fn get_code(&self) -> LIBRA_ERRNO {
        match self {
            LibrashaderError::UnknownError(_) => LIBRA_ERRNO::UNKNOWN_ERROR,
            LibrashaderError::InvalidParameter(_) => LIBRA_ERRNO::INVALID_PARAMETER,
            LibrashaderError::InvalidString(_) => LIBRA_ERRNO::INVALID_STRING,
            LibrashaderError::PresetError(_) => LIBRA_ERRNO::PRESET_ERROR,
            LibrashaderError::PreprocessError(_) => LIBRA_ERRNO::PREPROCESS_ERROR,
            LibrashaderError::ShaderCompileError(_) | LibrashaderError::ShaderReflectError(_) => {
                LIBRA_ERRNO::REFLECT_ERROR
            }
            LibrashaderError::UnknownShaderParameter(_) => LIBRA_ERRNO::SHADER_PARAMETER_ERROR,
            #[cfg(feature = "runtime-opengl")]
            LibrashaderError::OpenGlFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
            #[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
            LibrashaderError::D3D11FilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
            #[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
            LibrashaderError::D3D12FilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
            #[cfg(all(target_os = "windows", feature = "runtime-d3d9"))]
            LibrashaderError::D3D9FilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
            #[cfg(feature = "runtime-vulkan")]
            LibrashaderError::VulkanFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
            #[cfg(all(target_vendor = "apple", feature = "runtime-metal"))]
            LibrashaderError::MetalFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
            LibrashaderError::Infallible(_) => LIBRA_ERRNO::UNKNOWN_ERROR,
        }
    }

    /// Get the inner code of the runtime error
    pub(crate) const fn get_runtime_code(&self) -> LIBRA_ERRNO {
        match self {
            #[cfg(feature = "runtime-opengl")]
            LibrashaderError::OpenGlFilterError(ogl) => match ogl {
                librashader::runtime::gl::error::FilterChainError::FramebufferInit(_) => {
                    LIBRA_ERRNO::RUNTIME_ERROR
                }
                librashader::runtime::gl::error::FilterChainError::SpirvCrossReflectError(_) => {
                    LIBRA_ERRNO::REFLECT_ERROR
                }
                librashader::runtime::gl::error::FilterChainError::ShaderPresetError(_) => {
                    LIBRA_ERRNO::PRESET_ERROR
                }
                librashader::runtime::gl::error::FilterChainError::ShaderPreprocessError(_) => {
                    LIBRA_ERRNO::PREPROCESS_ERROR
                }
                librashader::runtime::gl::error::FilterChainError::ShaderCompileError(_)
                | librashader::runtime::gl::error::FilterChainError::ShaderReflectError(_) => {
                    LIBRA_ERRNO::REFLECT_ERROR
                }
                librashader::runtime::gl::error::FilterChainError::LutLoadError(_) => {
                    LIBRA_ERRNO::LUT_LOAD_ERROR
                }
                librashader::runtime::gl::error::FilterChainError::GLLoadError => {
                    LIBRA_ERRNO::RUNTIME_ERROR
                }
                librashader::runtime::gl::error::FilterChainError::GLLinkError(_)
                | librashader::runtime::gl::error::FilterChainError::GlCompileError(_)
                | librashader::runtime::gl::error::FilterChainError::GlProgramError(_) => {
                    LIBRA_ERRNO::COMPILE_ERROR
                }
                librashader::runtime::gl::error::FilterChainError::GlSamplerError
                | librashader::runtime::gl::error::FilterChainError::GlInvalidFramebuffer
                | librashader::runtime::gl::error::FilterChainError::GlError(_) => {
                    LIBRA_ERRNO::RUNTIME_ERROR
                }
                librashader::runtime::gl::error::FilterChainError::Infallible(_) => {
                    LIBRA_ERRNO::UNKNOWN_ERROR
                }
                _ => LIBRA_ERRNO::RUNTIME_ERROR,
            },
            #[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
            LibrashaderError::D3D11FilterError(d3d) => match d3d {
                librashader::runtime::d3d11::error::FilterChainError::Direct3DOperationError(_)
                | librashader::runtime::d3d11::error::FilterChainError::Direct3DError(_) => {
                    LIBRA_ERRNO::RUNTIME_ERROR
                }
                librashader::runtime::d3d11::error::FilterChainError::D3DCompileError(_) => {
                    LIBRA_ERRNO::COMPILE_ERROR
                }
                librashader::runtime::d3d11::error::FilterChainError::ShaderPresetError(_) => {
                    LIBRA_ERRNO::PRESET_ERROR
                }
                librashader::runtime::d3d11::error::FilterChainError::ShaderPreprocessError(_) => {
                    LIBRA_ERRNO::PREPROCESS_ERROR
                }
                librashader::runtime::d3d11::error::FilterChainError::ShaderCompileError(_)
                | librashader::runtime::d3d11::error::FilterChainError::ShaderReflectError(_) => {
                    LIBRA_ERRNO::REFLECT_ERROR
                }
                librashader::runtime::d3d11::error::FilterChainError::LutLoadError(_) => {
                    LIBRA_ERRNO::LUT_LOAD_ERROR
                }
                _ => LIBRA_ERRNO::RUNTIME_ERROR,
            },
            #[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
            LibrashaderError::D3D12FilterError(d3d) => match d3d {
                librashader::runtime::d3d12::error::FilterChainError::Direct3DOperationError(_)
                | librashader::runtime::d3d12::error::FilterChainError::Direct3DError(_) => {
                    LIBRA_ERRNO::RUNTIME_ERROR
                }
                librashader::runtime::d3d12::error::FilterChainError::ShaderPresetError(_) => {
                    LIBRA_ERRNO::PRESET_ERROR
                }
                librashader::runtime::d3d12::error::FilterChainError::ShaderPreprocessError(_) => {
                    LIBRA_ERRNO::PREPROCESS_ERROR
                }
                librashader::runtime::d3d12::error::FilterChainError::ShaderCompileError(_)
                | librashader::runtime::d3d12::error::FilterChainError::ShaderReflectError(_) => {
                    LIBRA_ERRNO::REFLECT_ERROR
                }
                librashader::runtime::d3d12::error::FilterChainError::LutLoadError(_) => {
                    LIBRA_ERRNO::LUT_LOAD_ERROR
                }
                librashader::runtime::d3d12::error::FilterChainError::HeapError(_)
                | librashader::runtime::d3d12::error::FilterChainError::AllocationError(_)
                | librashader::runtime::d3d12::error::FilterChainError::InvalidDimensionError(_) => {
                    LIBRA_ERRNO::RUNTIME_ERROR
                }
                librashader::runtime::d3d12::error::FilterChainError::Infallible(_) => {
                    LIBRA_ERRNO::UNKNOWN_ERROR
                }
                _ => LIBRA_ERRNO::RUNTIME_ERROR,
            },
            #[cfg(all(target_os = "windows", feature = "runtime-d3d9"))]
            LibrashaderError::D3D9FilterError(d3d) => match d3d {
                librashader::runtime::d3d9::error::FilterChainError::Direct3DOperationError(_)
                | librashader::runtime::d3d9::error::FilterChainError::Direct3DError(_) => {
                    LIBRA_ERRNO::RUNTIME_ERROR
                }
                librashader::runtime::d3d9::error::FilterChainError::ShaderPresetError(_) => {
                    LIBRA_ERRNO::PRESET_ERROR
                }
                librashader::runtime::d3d9::error::FilterChainError::ShaderPreprocessError(_) => {
                    LIBRA_ERRNO::PREPROCESS_ERROR
                }
                librashader::runtime::d3d9::error::FilterChainError::ShaderCompileError(_)
                | librashader::runtime::d3d9::error::FilterChainError::ShaderReflectError(_) => {
                    LIBRA_ERRNO::REFLECT_ERROR
                }
                librashader::runtime::d3d9::error::FilterChainError::LutLoadError(_) => {
                    LIBRA_ERRNO::LUT_LOAD_ERROR
                }
                librashader::runtime::d3d9::error::FilterChainError::UniformNameError(_) => {
                    LIBRA_ERRNO::INVALID_STRING
                }
                _ => LIBRA_ERRNO::RUNTIME_ERROR,
            },
            #[cfg(feature = "runtime-vulkan")]
            LibrashaderError::VulkanFilterError(vk) => match vk {
                librashader::runtime::vk::error::FilterChainError::HandleIsNull => {
                    LIBRA_ERRNO::INVALID_PARAMETER
                }
                librashader::runtime::vk::error::FilterChainError::ShaderPresetError(_) => {
                    LIBRA_ERRNO::PRESET_ERROR
                }
                librashader::runtime::vk::error::FilterChainError::ShaderPreprocessError(_) => {
                    LIBRA_ERRNO::PREPROCESS_ERROR
                }
                librashader::runtime::vk::error::FilterChainError::ShaderCompileError(_)
                | librashader::runtime::vk::error::FilterChainError::ShaderReflectError(_) => {
                    LIBRA_ERRNO::REFLECT_ERROR
                }
                librashader::runtime::vk::error::FilterChainError::LutLoadError(_) => {
                    LIBRA_ERRNO::LUT_LOAD_ERROR
                }
                librashader::runtime::vk::error::FilterChainError::VulkanResult(_)
                | librashader::runtime::vk::error::FilterChainError::VulkanMemoryError(_)
                | librashader::runtime::vk::error::FilterChainError::AllocationError(_)
                | librashader::runtime::vk::error::FilterChainError::AllocationDoesNotExist => {
                    LIBRA_ERRNO::RUNTIME_ERROR
                }
                librashader::runtime::vk::error::FilterChainError::Infallible(_) => {
                    LIBRA_ERRNO::UNKNOWN_ERROR
                }
                _ => LIBRA_ERRNO::RUNTIME_ERROR,
            },
            #[cfg(all(target_vendor = "apple", feature = "runtime-metal"))]
            LibrashaderError::MetalFilterError(mtl) => match mtl {
                librashader::runtime::mtl::error::FilterChainError::ShaderPresetError(_) => {
                    LIBRA_ERRNO::PRESET_ERROR
                }
                librashader::runtime::mtl::error::FilterChainError::ShaderPreprocessError(_) => {
                    LIBRA_ERRNO::PREPROCESS_ERROR
                }
                librashader::runtime::mtl::error::FilterChainError::ShaderCompileError(_)
                | librashader::runtime::mtl::error::FilterChainError::ShaderReflectError(_) => {
                    LIBRA_ERRNO::REFLECT_ERROR
                }
                librashader::runtime::mtl::error::FilterChainError::LutLoadError(_) => {
                    LIBRA_ERRNO::LUT_LOAD_ERROR
                }
                librashader::runtime::mtl::error::FilterChainError::SamplerError(_, _, _)
                | librashader::runtime::mtl::error::FilterChainError::BufferError
                | librashader::runtime::mtl::error::FilterChainError::MetalError(_)
                | librashader::runtime::mtl::error::FilterChainError::ShaderWrongEntryName
                | librashader::runtime::mtl::error::FilterChainError::FailedToCreateRenderPass
                | librashader::runtime::mtl::error::FilterChainError::FailedToCreateTexture
                | librashader::runtime::mtl::error::FilterChainError::FailedToCreateCommandBuffer => {
                    LIBRA_ERRNO::RUNTIME_ERROR
                }
                librashader::runtime::mtl::error::FilterChainError::Infallible(_) => {
                    LIBRA_ERRNO::UNKNOWN_ERROR
                }
                _ => LIBRA_ERRNO::RUNTIME_ERROR,
            },
            LibrashaderError::Infallible(_) => LIBRA_ERRNO::UNKNOWN_ERROR,
            _ => self.get_code(),
        }
    }

    pub(crate) const fn ok() -> libra_error_t {
        None
    }

    pub(crate) fn export(self) -> libra_error_t {
        NonNull::new(Box::into_raw(Box::new(self)))
    }
}

macro_rules! assert_non_null {
    (@EXPORT $value:ident) => {
        if $value.is_null() || !$crate::ffi::ptr_is_aligned($value) {
            return $crate::error::LibrashaderError::InvalidParameter(stringify!($value)).export();
        }
    };
    ($value:ident) => {
        if $value.is_null() || !$crate::ffi::ptr_is_aligned($value) {
            return Err($crate::error::LibrashaderError::InvalidParameter(
                stringify!($value),
            ));
        }
    };
}

macro_rules! assert_some_ptr {
    ($value:ident) => {
        if $value.is_none() {
            return Err($crate::error::LibrashaderError::InvalidParameter(
                stringify!($value),
            ));
        }

        let $value = unsafe { $value.as_ref().unwrap_unchecked().as_ref() };
    };
    (mut $value:ident) => {
        if $value.is_none() {
            return Err($crate::error::LibrashaderError::InvalidParameter(
                stringify!($value),
            ));
        }

        let $value = unsafe { $value.as_mut().unwrap_unchecked().as_mut() };
    };
}

use crate::ctypes::libra_error_t;
pub(crate) use assert_non_null;

// pub(crate) use assert_some;
pub(crate) use assert_some_ptr;