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 [`Sink`] type and [`sink`] function.

use crate::io::{Result, Write};

/// A type that discards writes.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default)]
pub struct Sink;
/// Constructs a new [`Sink`] object.
#[inline(always)]
#[must_use]
pub const fn sink() -> Sink {
	Sink
}

impl Write for Sink {
	#[inline]
	fn write(&mut self, buf: &[u8]) -> Result<usize> {
		Ok(buf.len())
	}

	#[inline(always)]
	fn write_all(&mut self, _buf: &[u8]) -> Result<()> {
		Ok(())
	}

	#[inline(always)]
	fn flush(&mut self) -> Result<()> {
		Ok(())
	}
}

impl Write for &Sink {
	#[inline]
	fn write(&mut self, buf: &[u8]) -> Result<usize> {
		Ok(buf.len())
	}

	#[inline(always)]
	fn write_all(&mut self, _buf: &[u8]) -> Result<()> {
		Ok(())
	}

	#[inline(always)]
	fn flush(&mut self) -> Result<()> {
		Ok(())
	}
}