java_diff_utils_rs/patch/
error.rs1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum DiffError {
7 General(String),
9 PatchFailed(String),
11 UnsupportedOperation(String),
13}
14
15impl DiffError {
16 pub fn new(msg: impl Into<String>) -> Self {
18 Self::General(msg.into())
19 }
20
21 pub fn patch_failed(msg: impl Into<String>) -> Self {
23 Self::PatchFailed(msg.into())
24 }
25
26 pub fn unsupported(msg: impl Into<String>) -> Self {
28 Self::UnsupportedOperation(msg.into())
29 }
30}
31
32impl fmt::Display for DiffError {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 match self {
35 Self::General(msg) => write!(f, "{msg}"),
36 Self::PatchFailed(msg) => write!(f, "Patch failed: {msg}"),
37 Self::UnsupportedOperation(msg) => write!(f, "Unsupported operation: {msg}"),
38 }
39 }
40}
41
42impl Error for DiffError {}
43
44impl From<String> for DiffError {
45 fn from(msg: String) -> Self {
46 Self::General(msg)
47 }
48}
49
50impl From<&str> for DiffError {
51 fn from(msg: &str) -> Self {
52 Self::General(msg.to_string())
53 }
54}
55
56pub type PatchError = DiffError;
58pub type PatchFailedException = DiffError;