| Crates.io | multitype |
| lib.rs | multitype |
| version | 0.19.1 |
| created_at | 2025-08-13 09:41:15.163946+00 |
| updated_at | 2026-01-21 14:53:44.801757+00 |
| description | Fundamental type traits. |
| homepage | |
| repository | https://mandelbrot.dk/bjoernager/multitype/ |
| max_upload_size | |
| id | 1793474 |
| size | 179,972 |
MultiType is Rust a crate for generalising fundamental types via traits.
MultiType provideds 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.
The complete list of abstraction traits is:
Arithmetic
Integral
SignedUnsignedFloatingPointNote that all traits provided by this crate are sealed and cannot be implemented by third-party crates (at least currently).
A generic Fibonacci sequence:
use multitype::Uint;
fn f<T: Uint>(x: T) -> T {
let mut y = T::from(0u8);
let mut y_m1 = T::from(0u8);
let mut y_m2 = T::from(1u8);
let mut i = T::from(0u8);
while i < x {
y = y_m1 + y_m2;
y_m2 = y_m1;
y_m1 = y;
i += T::from(1u8);
}
y
}
assert_eq!(f(0u8), 0);
assert_eq!(f(1u8), 1);
assert_eq!(f(2u16), 1);
assert_eq!(f(3u16), 2);
assert_eq!(f(4u32), 3);
assert_eq!(f(5u32), 5);
assert_eq!(f(6u64), 8);
assert_eq!(f(7u64), 13);
Default features:
allocstdDependency features:
alloc: Enables compatibility with alloc facilitiesstd: Enables compatibility with std facilitiesUnstable features:
f16: Enables support for f16f128: Enables support for f128nightly_backports: Enables backports for nightly itemsunstable_docs: Enables unstable documentation featuresUnstable gates can be expected to be removed as their facilities stabilise.
Nightly backports will match the current, nightly interfaces provided by rustc. A change in rustc will thus be reflected here along with a bump in the minor version.
Conversely, when a nightly item is stabilised in rustc, the corresponding nightly backport will be released from the feature gate in a minor version bump.
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 © 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.