Crate bounded_integer [] [src]

Provides bounded integers, integer types which are restricted to a range of values. These types are created by implementing the BoundedInteger trait for C-like enums.

This crate provides macros for generating implementations of BoundedInteger, Into, and arithmetic traits from std::ops. On nightly Rust, the bounded-integer-plugin crate provides a procedural macro for generating enums with variants for a range.

bounded-integer is on Crates.io and GitHub.

Examples

Nightly

#![feature(plugin)]
#![plugin(bounded_integer_plugin)]

#[macro_use]
extern crate bounded_integer;

bounded_integer! {
    /// Value that can fit in a nibble.
    #[derive(Debug)]
    pub enum Nibble: i8 { -8...7 }
}

Stable

The above example is equivalent to the following.

#[macro_use]
extern crate bounded_integer;

/// Value that can fit in a nibble.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(i8)]
pub enum Nibble {
    N8 = -8, N7, N6, N5, N4, N3, N2, N1, Z0, P1, P2, P3, P4, P5, P6, P7
}
bounded_integer_impls!(Nibble, i8, Nibble::N8, Nibble::P7);

Macros

bounded_integer_add_repr_impls

Implements std::ops::Add<Self::Repr> for a BoundedInteger.

bounded_integer_add_self_impls

Implements std::ops::Add<Self> for a BoundedInteger.

bounded_integer_div_repr_impls

Implements std::ops::Div<Self::Repr> for a BoundedInteger.

bounded_integer_div_self_impls

Implements std::ops::Div<Self> for a BoundedInteger.

bounded_integer_impl

Implements BoundedInteger for a C-like enum with contiguous variants.

bounded_integer_impls

Implements all bounded integer traits for a C-like enum with contiguous variants.

bounded_integer_into_repr_impl

Implements Into<Self::Repr> for a BoundedInteger.

bounded_integer_mul_repr_impls

Implements std::ops::Mul<Self::Repr> for a BoundedInteger.

bounded_integer_mul_self_impls

Implements std::ops::Mul<Self> for a BoundedInteger.

bounded_integer_neg_impls

Implements std::ops::Neg for a BoundedInteger.

bounded_integer_rem_repr_impls

Implements std::ops::Rem<Self::Repr> for a BoundedInteger.

bounded_integer_rem_self_impls

Implements std::ops::Rem<Self> for a BoundedInteger.

bounded_integer_sub_repr_impls

Implements std::ops::Sub<Self::Repr> for a BoundedInteger.

bounded_integer_sub_self_impls

Implements std::ops::Sub<Self> for a BoundedInteger.

Traits

BoundedInteger

Bounded integers.

Repr

Integer representation.