Skip to main content

harmos_runtime/filesystem/
error.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16// Standard Library Imports
17use std::{io, path::PathBuf};
18// Third Party Imports
19
20// Local Imports
21
22/* === Constants === */
23
24/* === Macros === */
25
26/* === Type Aliases === */
27
28pub type Result<T, E = Error> = std::result::Result<T, E>;
29
30/* === Structs === */
31
32/* === Enums === */
33
34#[derive(Debug, thiserror::Error)]
35pub enum Error {
36    #[error("cannot {operation} {path}: {source}")]
37    Publication {
38        operation: &'static str,
39        path: PathBuf,
40
41        #[source]
42        source: io::Error,
43    },
44}
45
46/* === Traits === */
47
48/* === Implementations === */
49
50impl Error {
51    pub(crate) fn publication(operation: &'static str, path: &std::path::Path, source: io::Error) -> Self {
52        Self::Publication { operation, path: path.to_owned(), source }
53    }
54
55    pub fn kind(&self) -> io::ErrorKind {
56        let Self::Publication { source, .. } = self;
57        source.kind()
58    }
59}
60
61impl From<Error> for io::Error {
62    fn from(error: Error) -> Self {
63        let Error::Publication { source, .. } = error;
64        source
65    }
66}
67
68/* === Public Functions === */
69
70/* === Private Functions === */
71
72/* === Tests === */