[][src]Crate funty

fundamental types

This crate provides trait unification of the Rust fundamental numbers, 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 IsNumber. 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 IsInteger and IsFloat. The former fills out the API of f32 and f64, while the latter covers all of the iN and uN numbers.

Lastly, IsInteger splits further, into IsSigned and IsUnsigned. 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

AtLeast8

Declare that a type is eight or more bits wide.

AtLeast16

Declare that a type is sixteen or more bits wide.

AtLeast32

Declare that a type is thirty-two or more bits wide.

AtLeast64

Declare that a type is sixty-four or more bits wide.

AtLeast128

Declare that a type is one hundred twenty-eight or more bits wide.

AtMost8

Declare that a type is eight or fewer bits wide.

AtMost16

Declare that a type is sixteen or fewer bits wide.

AtMost32

Declare that a type is thirty-two or fewer bits wide.

AtMost64

Declare that a type is sixty-four or fewer bits wide.

AtMost128

Declare that a type is one hundred twenty-eight or fewer bits wide.

Is8

Declare that a type is exactly eight bits wide.

Is16

Declare that a type is exactly sixteen bits wide.

Is32

Declare that a type is exactly thirty-two bits wide.

Is64

Declare that a type is exactly sixty-four bits wide.

Is128

Declare that a type is exactly one hundred twenty-eight bits wide.

IsFloat

Declare that a type is a floating-point number.

IsInteger

Declare that a type is a fixed-point integer.

IsNumber

Declare that a type is an abstract number.

IsSigned

Declare that a type is a signed integer.

IsUnsigned

Declare that a type is an unsigned integer.