citro3d/
error.rs

1//! General-purpose error and result types returned by public APIs of this crate.
2
3use std::ffi::NulError;
4use std::num::TryFromIntError;
5use std::sync::TryLockError;
6
7/// The common result type returned by `citro3d` functions.
8pub type Result<T> = std::result::Result<T, Error>;
9
10// TODO probably want a similar type to ctru::Result to make it easier to convert
11// nonzero result codes to errors.
12
13/// The common error type that may be returned by `citro3d` functions.
14#[non_exhaustive]
15#[derive(Debug)]
16pub enum Error {
17    /// C3D error code.
18    System(libc::c_int),
19    /// A C3D object or context could not be initialized.
20    FailedToInitialize,
21    /// A size parameter was specified that cannot be converted to the proper type.
22    InvalidSize,
23    /// Failed to select the given render target for drawing to.
24    InvalidRenderTarget,
25    /// Indicates that a reference could not be obtained because a lock is already
26    /// held on the requested object.
27    LockHeld,
28    /// Indicates that too many vertex attributes were registered (max 12 supported).
29    TooManyAttributes,
30    /// Indicates that too many vertex buffer objects were registered (max 12 supported).
31    TooManyBuffers,
32    /// The given memory could not be converted to a physical address for sharing
33    /// with the GPU. Data should be allocated with [`ctru::linear`].
34    InvalidMemoryLocation,
35    /// The given name was not valid for the requested purpose.
36    InvalidName,
37    /// The requested resource could not be found.
38    NotFound,
39    /// Attempted to use an index that was out of bounds.
40    IndexOutOfBounds {
41        /// The index used.
42        idx: libc::c_int,
43        /// The length of the collection.
44        len: libc::c_int,
45    },
46}
47
48impl From<TryFromIntError> for Error {
49    fn from(_: TryFromIntError) -> Self {
50        Self::InvalidSize
51    }
52}
53
54impl<T> From<TryLockError<T>> for Error {
55    fn from(_: TryLockError<T>) -> Self {
56        Self::LockHeld
57    }
58}
59
60impl From<NulError> for Error {
61    fn from(_: NulError) -> Self {
62        Self::InvalidName
63    }
64}