multitype 0.21.0

Arithmetic type traits.
Documentation
// Copyright 2025-2026 Gabriel Bjørnager Jensen.
//
// SPDX: MIT OR Apache-2.0

//! MultiType is a crate for generalising
//!
//! MultiType provides traits such as [`Unsigned`]
//! and [`FloatingPoint`] to abstract over a set of
//! equivalent primitive types. These traits are
//! intended to provide one-to-one copies of the
//! primary interfaces that the primitive types
//! define.
//!
//! # Overview
//!
//! The complete list of abstraction traits is:
//!
//! * [`Integral`]
//!   * [`Signed`]
//!   * [`Unsigned`]
//! * [`FloatingPoint`]
//!   * [`StdFloatingPoint`]
//!
#![cfg_attr(not(feature = "std"), doc = "[`StdFloatingPoint`]: <https://docs.rs/multitype/latest/multitype/trait.StdFloatingPoint.html>\n")]
//!
//! # Examples
//!
//! A generic Fibonacci sequence:
//!
//! ```rust
//! use multitype::Unsigned;
//!
//! fn f<T: Unsigned + From<u8>>(x: T) -> T {
//!     let mut y    = T::from(0_u8);
//!     let mut y_m1 = T::from(0_u8);
//!     let mut y_m2 = T::from(1_u8);
//!
//!     let mut i = T::from(0_u8);
//!     while i < x {
//!         y = y_m1 + y_m2;
//!
//!         y_m2 = y_m1;
//!         y_m1 = y;
//!
//!         i += T::from(1_u8);
//!     }
//!
//!     y
//! }
//!
//! assert_eq!(f(0_u8),    0);
//! assert_eq!(f(1_u8),    1);
//!
//! assert_eq!(f(2_u16),   1);
//! assert_eq!(f(3_u16),   2);
//!
//! assert_eq!(f(4_u32),   3);
//! assert_eq!(f(5_u32),   5);
//!
//! assert_eq!(f(6_u64),   8);
//! assert_eq!(f(7_u64),  13);
//!
//! assert_eq!(f(8_u128), 21);
//! assert_eq!(f(9_u128), 34);
//! ```
//!
//! # Feature gates
//!
//! Default features:
//! * `alloc`
//! * `std`
//!
//! Dependency features:
#![cfg_attr(feature = "alloc",      doc = "* `alloc`: Enables compatibility with [`alloc`] facilities\n")]
#![cfg_attr(not(feature = "alloc"), doc = "* `alloc`: Enables compatibility with `alloc` facilities\n")]
#![cfg_attr(feature = "std",        doc = "* `std`: Enables compatibility with [`std`] facilities\n")]
#![cfg_attr(not(feature = "std"),   doc = "* `std`: Enables compatibility with `std` facilities\n")]
//!
//! Unstable features:
//! * `f128`: Enables support for [`f128`]
//! * `f16`: Enables support for [`f16`]
//! * `unstable_docs`: Enables unstable documentation features
//!
//! Unstable gates can be expected to be removed as
//! their facilities stabilise.
//!
//! # MSRV policy
//!
//! The goal of MultiType is to provide generic
//! traits that bind as much of the standard
//! interfaces as possible. Items that are added
//! after the MSRV will be backported.
//!
//! # Copyright and licence
//!
//! Copyright &#169; 2025-2026 Gabriel Bjørnager
//! Jensen.
//!
//! MultiType is distributed under either an MIT
//! licence (see `LICENCE-MIT`) or version 2.0 of
//! the Apache License (see `LICENCE-APACHE`), at
//! your option.

#![doc(html_logo_url = "https://codeberg.org/bjoernager/multitype/raw/branch/master/DOC-ICON.svg")]

#![no_std]

#![cfg_attr(feature = "f16", feature(f16))]

#![cfg_attr(feature = "f128", feature(f128))]

#![cfg_attr(feature = "unstable_docs", feature(doc_cfg, intra_doc_pointers))]

extern crate self as multitype;

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

mod carrying_mul_add;
mod floating_point;
mod integral;
mod one_less_than_next_power_of_two;
mod signed;
mod std_floating_point;
mod unsigned;

pub use floating_point::FloatingPoint;
pub use integral::Integral;
pub use signed::Signed;
pub use unsigned::Unsigned;

#[cfg(feature = "std")]
pub use std_floating_point::StdFloatingPoint;

use carrying_mul_add::CarryingMulAdd;

#[allow(unused_imports)]
use one_less_than_next_power_of_two::OneLessThanNextPowerOfTwo;