indexbus_platform_ops/
errors.rs

1//! Error types and `Result` aliases.
2//!
3//! **Error semantics**
4//! - Errors are intended to be human-readable diagnostics suitable for logs.
5//! - Most APIs in this crate are best-effort operational probes; callers should decide whether a
6//!   finding is fatal for their environment.
7
8use std::fmt;
9
10/// Result type used by this crate.
11pub type Result<T> = std::result::Result<T, Error>;
12
13#[derive(Debug)]
14/// An operational error.
15pub struct Error {
16    msg: String,
17}
18
19impl Error {
20    /// Construct an error message.
21    pub fn msg(msg: impl Into<String>) -> Self {
22        Self { msg: msg.into() }
23    }
24}
25
26impl fmt::Display for Error {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        write!(f, "{}", self.msg)
29    }
30}
31
32impl std::error::Error for Error {}
33
34impl From<std::io::Error> for Error {
35    fn from(value: std::io::Error) -> Self {
36        Self::msg(value.to_string())
37    }
38}