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
// ctl_error.rs
use thiserror::Error;

#[derive(Debug, Error)]
pub enum SysctlError {
    #[error("no such sysctl: {0}")]
    NotFound(String),

    #[error("no matching type for value")]
    #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos")))]
    UnknownType,

    #[error("Error extracting value")]
    ExtractionError,

    #[error("Error parsing value")]
    ParseError,

    #[error("Support for type not implemented")]
    MissingImplementation,

    #[error("IO Error: {0}")]
    IoError(#[from] std::io::Error),

    #[error("Error parsing UTF-8 data: {0}")]
    Utf8Error(#[from] std::str::Utf8Error),

    #[error("Value is not readable")]
    NoReadAccess,

    #[error("Value is not writeable")]
    NoWriteAccess,

    #[error("Not supported by this platform")]
    NotSupported,

    #[error(
        "sysctl returned a short read: read {read} bytes, while a size of {reported} was reported"
    )]
    ShortRead { read: usize, reported: usize },

    #[error("Error reading C String: String was not NUL-terminated.")]
    InvalidCStr(#[from] std::ffi::FromBytesWithNulError),

    #[error("Error Rust string contains nul bytes")]
    InvalidCString(#[from] std::ffi::NulError),
}