edit/
apperr.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Provides a transparent error type for edit.
5
6use std::{io, result};
7
8use crate::sys;
9
10pub const APP_ICU_MISSING: Error = Error::new_app(0);
11
12/// Edit's transparent `Result` type.
13pub type Result<T> = result::Result<T, Error>;
14
15/// Edit's transparent `Error` type.
16/// Abstracts over system and application errors.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum Error {
19    App(u32),
20    Icu(u32),
21    Sys(u32),
22}
23
24impl Error {
25    pub const fn new_app(code: u32) -> Self {
26        Self::App(code)
27    }
28
29    pub const fn new_icu(code: u32) -> Self {
30        Self::Icu(code)
31    }
32
33    pub const fn new_sys(code: u32) -> Self {
34        Self::Sys(code)
35    }
36}
37
38impl From<io::Error> for Error {
39    fn from(err: io::Error) -> Self {
40        sys::io_error_to_apperr(err)
41    }
42}