build_fs_tree/build/
error.rs

1use derive_more::{Display, Error};
2use std::fmt::{self, Debug, Formatter};
3
4/// Error caused by [`Build::build`](crate::Build::build).
5#[derive(Debug, Display, Error)]
6#[display("{operation} {path:?}: {error}")]
7#[display(bound(Path: Debug, Error: Display))]
8pub struct BuildError<Path, Error> {
9    /// Operation that caused the error.
10    pub operation: FailedOperation,
11    /// Path where the error occurred.
12    pub path: Path,
13    /// The error.
14    pub error: Error,
15}
16
17/// Operation that causes an error.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum FailedOperation {
20    /// The operation was to write a file.
21    WriteFile,
22    /// The operation was to create a directory.
23    CreateDir,
24}
25
26impl FailedOperation {
27    /// Convert to a string.
28    pub const fn name(self) -> &'static str {
29        use FailedOperation::*;
30        match self {
31            WriteFile => "write_file",
32            CreateDir => "create_dir",
33        }
34    }
35}
36
37impl fmt::Display for FailedOperation {
38    fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), fmt::Error> {
39        write!(formatter, "{}", self.name())
40    }
41}