mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-06-02 23:29:34 +00:00
30 lines
731 B
Rust
30 lines
731 B
Rust
/// Simple wrapper around a pointer to a value or an error.
|
|
///
|
|
/// Pointer is not guaranteed. You should check the error field before
|
|
/// dereferencing the pointer.
|
|
#[repr(C)]
|
|
pub struct PointerResult<Type, Error> {
|
|
pub value: *mut Type,
|
|
pub error: Error,
|
|
}
|
|
|
|
impl<Type, Error: Default> PointerResult<Type, Error> {
|
|
pub fn from_pointer(pointer: *mut Type) -> Self {
|
|
Self {
|
|
value: pointer,
|
|
error: Error::default(),
|
|
}
|
|
}
|
|
|
|
pub fn from_value(value: Type) -> Self {
|
|
Self::from_pointer(Box::into_raw(Box::new(value)))
|
|
}
|
|
|
|
pub const fn from_error(error: Error) -> Self {
|
|
Self {
|
|
value: std::ptr::null_mut(),
|
|
error,
|
|
}
|
|
}
|
|
}
|