1#[cfg(feature = "std")]
2use std::{error::Error, fmt};
34#[cfg(not(feature = "std"))]
5use core::fmt;
67/// Runtime error when a `build()` method is called and one or more required fields
8/// do not have a value.
9#[derive(Debug, Clone)]
10pub struct UninitializedFieldError(&'static str);
1112impl UninitializedFieldError {
13/// Create a new `UnitializedFieldError` for the specified field name.
14pub fn new(field_name: &'static str) -> Self {
15 UninitializedFieldError(field_name)
16 }
1718/// Get the name of the first-declared field that wasn't initialized
19pub fn field_name(&self) -> &'static str {
20self.0
21}
22}
2324impl fmt::Display for UninitializedFieldError {
25fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26write!(f, "Field not initialized: {}", self.0)
27 }
28}
2930#[cfg(feature = "std")]
31impl Error for UninitializedFieldError {}
3233impl From<&'static str> for UninitializedFieldError {
34fn from(field_name: &'static str) -> Self {
35Self::new(field_name)
36 }
37}