derive_more/
ops.rs
1use core::fmt;
4
5#[derive(Clone, Copy, Debug)]
8pub struct UnitError {
9 operation_name: &'static str,
10}
11
12impl UnitError {
13 #[doc(hidden)]
14 #[must_use]
15 #[inline]
16 pub const fn new(operation_name: &'static str) -> Self {
17 Self { operation_name }
18 }
19}
20
21impl fmt::Display for UnitError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "Cannot {}() unit variants", self.operation_name)
24 }
25}
26
27#[cfg(feature = "std")]
28impl std::error::Error for UnitError {}