iri_string/types/generic/
error.rs1use core::fmt;
4
5#[cfg(feature = "std")]
6use std::error;
7
8use crate::validate::Error;
9
10pub struct CreationError<T> {
19 source: T,
21 error: Error,
23}
24
25impl<T> CreationError<T> {
26 #[must_use]
28 pub fn into_source(self) -> T {
29 self.source
30 }
31
32 #[must_use]
34 pub fn validation_error(&self) -> Error {
35 self.error
36 }
37
38 #[must_use]
40 pub(crate) fn new(error: Error, source: T) -> Self {
41 Self { source, error }
42 }
43}
44
45impl<T: fmt::Debug> fmt::Debug for CreationError<T> {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 f.debug_struct("CreationError")
48 .field("source", &self.source)
49 .field("error", &self.error)
50 .finish()
51 }
52}
53
54impl<T: Clone> Clone for CreationError<T> {
55 fn clone(&self) -> Self {
56 Self {
57 source: self.source.clone(),
58 error: self.error,
59 }
60 }
61}
62
63impl<T> fmt::Display for CreationError<T> {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 self.error.fmt(f)
66 }
67}
68
69#[cfg(feature = "std")]
70impl<T: fmt::Debug> error::Error for CreationError<T> {}