oct/error/
non_zero_decode_error.rs

1// Copyright 2024-2025 Gabriel Bjørnager Jensen.
2//
3// This Source Code Form is subject to the terms of
4// the Mozilla Public License, v. 2.0. If a copy of
5// the MPL was not distributed with this file, you
6// can obtain one at:
7// <https://mozilla.org/MPL/2.0/>.
8
9use core::convert::Infallible;
10use core::error::Error;
11use core::fmt::{self, Display, Formatter};
12
13/// A non-zero integer could not be decoded.
14///
15/// The implementations of [`Decode`](crate::decode::Decode) for <code>[NonZero](core::num::NonZero)&lt;T&gt;</code> yield this error type if decoding `T` yields zero.
16#[derive(Debug, Eq, PartialEq)]
17pub struct NonZeroDecodeError;
18
19impl Display for NonZeroDecodeError {
20	#[inline]
21	fn fmt(&self, f: &mut Formatter) -> fmt::Result {
22		write!(f, "expected non-zero integer but found `0`")
23	}
24}
25
26impl Error for NonZeroDecodeError { }
27
28impl From<Infallible> for NonZeroDecodeError {
29	#[inline(always)]
30	fn from(_value: Infallible) -> Self {
31		unreachable!()
32	}
33}