Coverage Report

Created: 2025-11-16 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/mesa3d_util-0.1.75/error.rs
Line
Count
Source
1
// Copyright 2025 Google
2
// SPDX-License-Identifier: MIT
3
4
use std::ffi::NulError;
5
use std::io::Error as IoError;
6
use std::num::ParseIntError;
7
use std::num::TryFromIntError;
8
use std::str::Utf8Error;
9
10
use remain::sorted;
11
use rustix::io::Errno as RustixError;
12
use thiserror::Error;
13
14
/// An error generated while using this crate.
15
#[sorted]
16
#[derive(Error, Debug)]
17
pub enum MesaError {
18
    /// An error with the MesaHandle
19
    #[error("invalid Mesa handle")]
20
    InvalidMesaHandle,
21
    /// An input/output error occurred.
22
    #[error("an input/output error occurred: {0}")]
23
    IoError(IoError),
24
    /// Nul crate error.
25
    #[error("Nul Error occurred {0}")]
26
    NulError(NulError),
27
    /// An attempted integer parsing failed.
28
    #[error("int parsing failed: {0}")]
29
    ParseIntError(ParseIntError),
30
    /// Rustix crate error.
31
    #[error("The errno is {0}")]
32
    RustixError(RustixError),
33
    /// An attempted integer conversion failed.
34
    #[error("int conversion failed: {0}")]
35
    TryFromIntError(TryFromIntError),
36
    /// The command is unsupported.
37
    #[error("the requested function is not implemented")]
38
    Unsupported,
39
    /// Utf8 error.
40
    #[error("an utf8 error occurred: {0}")]
41
    Utf8Error(Utf8Error),
42
    /// An error with a free form context, similar to anyhow
43
    #[error("operation failed: {0}")]
44
    WithContext(&'static str),
45
}
46
47
#[cfg(any(target_os = "android", target_os = "linux"))]
48
impl From<RustixError> for MesaError {
49
0
    fn from(e: RustixError) -> MesaError {
50
0
        MesaError::RustixError(e)
51
0
    }
52
}
53
54
impl From<NulError> for MesaError {
55
0
    fn from(e: NulError) -> MesaError {
56
0
        MesaError::NulError(e)
57
0
    }
58
}
59
60
impl From<IoError> for MesaError {
61
0
    fn from(e: IoError) -> MesaError {
62
0
        MesaError::IoError(e)
63
0
    }
64
}
65
66
impl From<ParseIntError> for MesaError {
67
0
    fn from(e: ParseIntError) -> MesaError {
68
0
        MesaError::ParseIntError(e)
69
0
    }
70
}
71
72
impl From<TryFromIntError> for MesaError {
73
0
    fn from(e: TryFromIntError) -> MesaError {
74
0
        MesaError::TryFromIntError(e)
75
0
    }
76
}
77
78
impl From<Utf8Error> for MesaError {
79
0
    fn from(e: Utf8Error) -> MesaError {
80
0
        MesaError::Utf8Error(e)
81
0
    }
82
}
83
84
/// The result of an operation in this crate.
85
pub type MesaResult<T> = std::result::Result<T, MesaError>;