derive_builder_fork_arti/
error.rs1#[cfg(feature = "std")]
2use std::{error::Error, fmt};
3
4#[cfg(not(feature = "std"))]
5use core::fmt;
6
7#[derive(Debug, Clone)]
10pub struct UninitializedFieldError(&'static str);
11
12impl UninitializedFieldError {
13 pub fn new(field_name: &'static str) -> Self {
15 UninitializedFieldError(field_name)
16 }
17
18 pub fn field_name(&self) -> &'static str {
20 self.0
21 }
22}
23
24impl fmt::Display for UninitializedFieldError {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26 write!(f, "Field not initialized: {}", self.0)
27 }
28}
29
30#[cfg(feature = "std")]
31impl Error for UninitializedFieldError {}
32
33impl From<&'static str> for UninitializedFieldError {
34 fn from(field_name: &'static str) -> Self {
35 Self::new(field_name)
36 }
37}
38
39#[derive(Debug, Clone)]
48pub struct SubfieldBuildError<E>(&'static str, E);
49
50impl<E> SubfieldBuildError<E> {
51 pub fn new(field_name: &'static str, sub_builder_error: E) -> Self {
53 SubfieldBuildError(field_name, sub_builder_error)
54 }
55
56 pub fn field_name(&self) -> &'static str {
58 self.0
59 }
60
61 pub fn sub_builder_error(&self) -> &E {
63 &self.1
64 }
65
66 pub fn into_parts(self) -> (&'static str, E) {
68 (self.0, self.1)
69 }
70}
71
72impl<E> fmt::Display for SubfieldBuildError<E>
73where
74 E: fmt::Display,
75{
76 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
77 write!(f, "in {}: {}", self.0, self.1)
78 }
79}
80
81#[cfg(feature = "std")]
82impl<E> Error for SubfieldBuildError<E> where E: Error {}