cue_sdk/
errors.rs

1//! Contains the top level SDK error type, and `Result` type.
2use cue_sdk_sys as ffi;
3use num_traits::FromPrimitive;
4
5/// SdkErrors received from the iCUE SDK directly.
6#[derive(Debug, Copy, Clone, PartialEq, FromPrimitive)]
7#[repr(u32)]
8pub enum CueSdkError {
9    ServerNotFound = ffi::CorsairError_CE_ServerNotFound,
10    NoControl = ffi::CorsairError_CE_NoControl,
11    ProtocolHandshakeMissing = ffi::CorsairError_CE_ProtocolHandshakeMissing,
12    IncompatibleProtocol = ffi::CorsairError_CE_IncompatibleProtocol,
13    InvalidArguments = ffi::CorsairError_CE_InvalidArguments,
14}
15
16pub(crate) fn get_last_error() -> Option<CueSdkError> {
17    CueSdkError::from_u32(unsafe { cue_sdk_sys::CorsairGetLastError() })
18}
19
20/// A common `Result` type, defaulting the data to unit, and the error is an
21/// `Option<CueSdkError>`.
22///
23/// It is an option because it is possible for the SDK to return a failure on a given operation,
24/// but then when we check for the error, it says there is none, or (on a particularly bad day) it *could*
25/// give a value that isn't expected or documented.
26pub type CueSdkErrorResult<T = ()> = Result<T, Option<CueSdkError>>;