#[cfg(feature = "std")]
use std::{error::Error, fmt};
#[cfg(not(feature = "std"))]
use core::fmt;
#[derive(Debug, Clone)]
pub struct UninitializedFieldError(&'static str);
impl UninitializedFieldError {
pub fn new(field_name: &'static str) -> Self {
UninitializedFieldError(field_name)
}
pub fn field_name(&self) -> &'static str {
self.0
}
}
impl fmt::Display for UninitializedFieldError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Field not initialized: {}", self.0)
}
}
#[cfg(feature = "std")]
impl Error for UninitializedFieldError {}
impl From<&'static str> for UninitializedFieldError {
fn from(field_name: &'static str) -> Self {
Self::new(field_name)
}
}