MultiType
MultiType is Rust a crate for generalising fundamental types via traits.
MultiType provideds traits such as Uint and Float traits to abstract over a set of equivalent primitive types.
These traits are intended to provide one-to-one copies of the interfaces that the primitive types define.
Arithmetic types
MultiType defines different traits for generalising arithmetic types:
Uintforu8,u16,u32,u64,u128, andusize;Intfori8,i16,i32,i64,i128, andisize;Floatforf16,f32,f64, andf128.
Furthermore, StdFloat extends the Float trait with functionality that is typically only available in std's floating-point types.
Sized, arithmetic types
The basic, arithmetic traits guarantee a minimum size that is equivalent to the smallest member of its group, e.g. Uint is at least u8 and Float is at least f16.
Additionally, these three arithmetic traits have subtraits that guarantee wider types, for example:
i16and up implementIntLeast16;i32and up implementIntLeast32;- Etc.
The complete list of arithmetic traits is thus:
UintUintLeast16UintLeast32UintLeast64UintLeast128
IntIntLeast16IntLeast32IntLeast64IntLeast128
FloatStdFloatFloatLeast32FloatLeast64FloatLeast128
Array types
MultiType also provides the Array trait for generalising array types – most often over their length.
An example of this trait's usecase is actually in this crate:
Take, for instance, the definition of Uint: It has a Bytes associated type that is used by the bytewise constructors and destructors:
pub unsafe
Now, anyone that would want to use the output of to_ne_bytes:to_ne_bytes) wouldn't really have that many choices with regard to what to do with it.
So, MultiType defines the Array trait:
use Array;
pub unsafe
With it, it's possible for users to generically use Uint::to_ne_bytes as an array type through the trait methods.
Examples
A generic Fibonacci sequence:
use Uint;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Generic array indexing:
use f32;
use Array;
use Float;
assert_eq!;
assert_eq!;
assert_eq!;
Copyright & Licence.
Copyright © 2025 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.