1#[cfg(feature="patch")] pub mod patch;
2pub mod txt;
3pub mod diff;
4pub mod generic;
5mod vec_processor;
6mod map_processor;
7
8use std::borrow::Cow;
9use std::fmt;
10use std::fmt::Display;
11
12pub trait MismatchDoc<T> {
14 fn new(base: &T, input: &T) -> Result<Self, DocError> where Self: Sized;
15
16 fn is_intersect(&self, other: &Self) -> Result<bool, DocError>;
18
19 fn len(&self) -> usize;
20}
21
22pub trait MismatchDocMut<T> {
24
25 fn apply_mut(&self, input: &mut T, fail_fast: bool) -> Result<Vec<DocError>, DocError>;
29}
30
31pub trait MismatchDocCow<T> {
33 fn apply(&self, input: &T) -> Result<T, DocError>;
34}
35
36#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)]
38pub enum Mismatches {
39 #[cfg(feature="patch")]
40 Patch(patch::Mismatch),
42 Doc(diff::Mismatch),
44 Text(txt::Mismatch),
46}
47
48
49#[derive(Debug)]
50pub struct DocError(Cow<'static, str>);
51
52impl DocError {
53 fn new<E: Into<Cow<'static, str>>>(e: E) -> Self {
54 Self(e.into())
55 }
56}
57impl std::error::Error for DocError {}
58
59impl Display for DocError {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 write!(f, "{}", self.0)
62 }
63}
64
65impl Display for Mismatches {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67 match serde_json::to_string(&self) {
68 Ok(json) => write!(f, "{}", json),
69 Err(err) => write!(f, "ERR: {}", err)
70 }
71
72 }
73}
74
75#[cfg(test)]
76mod tests {
77 #[test]
78 fn test_compile() {
79 assert!(true);
80 }
81}