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/>.

//! Input/output facilities.
//!
//! This module is fundamentally a port of
//! [`std::io`]. It additionally provides the
//! [`Serialise`] and [`Deserialise`] traits.
//!
//! [`Serialise`]: trait@Serialise
//! [`Deserialise`]: trait@Deserialise
//!
#![cfg_attr(not(feature = "std"), doc = "[`std::io`]: <https://doc.rust-lang.org/nightly/std/io/index.html>")]
//!
//! Note that all ported items are only provided on
//! a bare bones basis; implementing the entirety of
//! `std::io` would either be massively inefficient
//! or extremely overcomplicated due to the extra
//! leverage that internal crates get (that we
//! wouldn't without a nightly compiler). See
//! [#48331] for information on the official port
//! into [`alloc`] and [`core`].
//!
//! [#48331]: <https://github.com/rust-lang/rust/issues/48331>
//!
#![cfg_attr(not(feature = "alloc"), doc = "[`alloc`]: <https://doc.rust-lang.org/nightly/alloc/index.html>")]
//!
//! # Examples
//!
#![cfg_attr(feature = "proc_macro", doc = include_str!("serdes_examples.md"))]

mod bytes;
mod _copy;
mod cursor;
mod deserialise;
mod empty;
mod error;
mod error_kind;
mod read;
mod repeat;
mod seek;
mod seek_from;
mod serialise;
mod simple_error;
mod sink;
mod write;

pub use bytes::Bytes;
pub use _copy::copy;
pub use cursor::Cursor;
pub use deserialise::Deserialise;
pub use empty::{Empty, empty};
pub use error::Error;
pub use error_kind::ErrorKind;
pub use read::Read;
pub use repeat::{Repeat, repeat};
pub use seek::Seek;
pub use seek_from::SeekFrom;
pub use serialise::Serialise;
pub use simple_error::SimpleError;
pub use sink::{Sink, sink};
pub use write::Write;

use error::ErrorData;

#[cfg(feature = "alloc")]
use error::CustomError;

#[cfg(feature = "alloc")]
pub use read::read_to_string;

/// An input/output result.
///
/// Equivalent to
/// <code>[core::result::Result]&lt;T, [Error]&gt;</code>.
pub type Result<T> = core::result::Result<T, Error>;

/// Implements [`Deserialise`] for the given type.
///
/// [`Deserialise`]: trait@Deserialise
#[cfg(feature = "proc_macro")]
#[doc(inline)]
pub use oct_macros::Deserialise;

/// Implements [`Serialise`] for the given type.
///
/// [`Serialise`]: trait@Serialise
#[cfg(feature = "proc_macro")]
#[doc(inline)]
pub use oct_macros::Serialise;

/// The default size of input/output buffers.
const DEFAULT_BUF_SIZE: usize = {
	let block_size = 512;

	let factor = if cfg!(feature = "std") {
		// NOTE: Hosted environments often have more
		// memory, in which case it would be effective to
		// use it.
		8
	} else {
		1
	};

	block_size * factor
};