1#[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}