Skip to content
/ anyint Public

a rust crate providing traits and structs for working with integers of any bit size

Notifications You must be signed in to change notification settings

brecert/anyint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

anyint — any bit sized integers

Latest Version Rust Documentation

This library provides traits and structs for working with integers of any bit size.

Compiler support: tested with rustc 1.61.0 nightly, unsure about support on lower versions

Example

use anyint::prelude::*;
use anyint::macros::{Int, int};

// int macro to make working with the types easier
assert_eq!(int!(0u6), int::<u8, 6>::new(0));
assert_eq!(int!(-32i6), int::<i8, 6>::new(-32));

// many of the same methods that the standard library integers have
let num = int!(63u6).wrapping_add(int!(3u6));
assert_eq!(num.0, 2);

// Int type macro to make working with the types easier
fn add(a: u16, b: u16) -> Int![u12] {
  int::new(a) + int::new(b)
}
assert_eq!(add(5, 10), int::new(15));

Details / Notes

The underlying representation of your integer will be what is provided for the anyint::int struct.

This is to keep performance reasonable and the implementations simple.

Most of the common methods that std integers have should also be implemented here, if there's any that's missing feel free to create an issue about it.

FAQ

  1. Is this crate no_std compatable?
    • Yes! Just add default-features = false.

About

a rust crate providing traits and structs for working with integers of any bit size

Topics

Resources

Stars

Watchers

Forks

Languages