Crate funty

source ·
Expand description

fundamental types

This crate provides trait unification of the Rust fundamental items, allowing users to declare the behavior they want from a number without committing to a single particular numeric type.

The number types can be categorized along two axes: behavior and width. Traits for each axis and group on that axis are provided:

Numeric Categories

The most general category is represented by the trait Numeric. It is implemented by all the numeric fundamentals, and includes only the traits that they all implement. This is an already-large amount: basic memory management, comparison, rendering, and numeric arithmetic.

The numbers are then split into Floating and Integral. The former fills out the API of f32 and f64, while the latter covers all of the iN and uN numbers.

Lastly, Integral splits further, into Signed and Unsigned. These provide the last specializations unique to the differences between iN and uN.

Width Categories

Every number implements the trait IsN for the N of its bit width. isize and usize implement the trait that matches their width on the target platform.

In addition, the trait groups AtLeastN and AtMostN enable clamping the range of acceptable widths to lower or upper bounds. These traits are equivalent to mem::size_of::<T>() >= N and mem::size_of::<T>() <= N, respectively.

!

Traits

  • Declare that a type is eight or more bits wide.
  • Declare that a type is sixteen or more bits wide.
  • Declare that a type is thirty-two or more bits wide.
  • Declare that a type is sixty-four or more bits wide.
  • Declare that a type is one hundred twenty-eight or more bits wide.
  • Declare that a type is eight or fewer bits wide.
  • Declare that a type is sixteen or fewer bits wide.
  • Declare that a type is thirty-two or fewer bits wide.
  • Declare that a type is sixty-four or fewer bits wide.
  • Declare that a type is one hundred twenty-eight or fewer bits wide.
  • Declare that a type is a floating-point number.
  • Declare that a type is one of the language fundamental types.
  • Declare that a type is a fixed-point integer.
  • Declare that a type is exactly eight bits wide.
  • Declare that a type is exactly sixteen bits wide.
  • Declare that a type is exactly thirty-two bits wide.
  • Declare that a type is exactly sixty-four bits wide.
  • Declare that a type is exactly one hundred twenty-eight bits wide.
  • Declare that a type is an abstract number.
  • Declare that a type is a signed integer.
  • Declare that a type is an unsigned integer.