oct 0.26.0

Octonary transcodings.
Documentation
// Copyright 2024-2025 Gabriel Bjørnager Jensen.
//
// This Source Code Form is subject to the terms of
// the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, you
// can obtain one at:
// <https://mozilla.org/MPL/2.0/>.

//! The [`SimpleError`] error type.

use crate::io::ErrorKind;

use core::fmt::{self, Display, Formatter};

// NOTE: Alignement ensures some padding bits in
// addresses.
/// An error kind with an error message.
///
/// Objects of this type are intended to be
/// allocated in static memory.
#[repr(align(4))]
#[derive(Clone, Copy, Debug)]
pub struct SimpleError {
	/// The error kind.
	kind: ErrorKind,

	/// The error message.
	message: &'static str,
}

impl SimpleError {
	/// Constructs a new, simple input/output error.
	#[inline]
	#[must_use]
	pub const fn new(kind: ErrorKind, message: &'static str) -> Self {
		Self { kind, message }
	}

	/// Retrieves the kind of error.
	#[inline(always)]
	#[must_use]
	pub const fn kind(&self) -> ErrorKind {
		self.kind
	}

	/// Retrieves the error message.
	#[inline(always)]
	#[must_use]
	pub const fn message(&self) -> &'static str {
		self.message
	}
}

impl Display for SimpleError {
	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
		write!(f, "{}: {}", self.kind, self.message)?;
		Ok(())
	}
}

impl core::error::Error for SimpleError {}