Expand description

unprim contains primitive types from 8 into 256 bit. it is unstable and not intended for production use.

use un_prim::*;

let a = U256::from(100);
let b = U256::from(2);

assert_eq!(a * b, 200u64.into());

Or you can use .into() method to init the types.

use un_prim::*;

let a: U24 = 100u64.into();
let b: U24 = 2u64.into();
let c: u32 = (a * b).into();

assert_eq!(c, 200);

You can use macro to define new types. In example if you want to define a type with 512 bit, you can use the macro.


use un_prim::*;

define!(U512, 64, "512 bit");

let a = U512::from(100);
let b = U512::from(2);
let c = a * b;
assert_eq!(c, 200u64.into());

Modules

Macros

Structs

24-bit unsigned integer represented as little-endian byte order.

40-bit unsigned integer represented as little-endian byte order.

48-bit unsigned integer represented as little-endian byte order.

56-bit unsigned integer represented as little-endian byte order.

72-bit unsigned integer represented as little-endian byte order.

80-bit unsigned integer represented as little-endian byte order.

88-bit unsigned integer represented as little-endian byte order.

96-bit unsigned integer represented as little-endian byte order.

104-bit unsigned integer represented as little-endian byte order.

112-bit unsigned integer represented as little-endian byte order.

120-bit unsigned integer represented as little-endian byte order.

136-bit unsigned integer represented as little-endian byte order.

144-bit unsigned integer represented as little-endian byte order.

152-bit unsigned integer represented as little-endian byte order.

160-bit unsigned integer represented as little-endian byte order.

168-bit unsigned integer represented as little-endian byte order.

176-bit unsigned integer represented as little-endian byte order.

184-bit unsigned integer represented as little-endian byte order.

192-bit unsigned integer represented as little-endian byte order.

200-bit unsigned integer represented as little-endian byte order.

208-bit unsigned integer represented as little-endian byte order.

216-bit unsigned integer represented as little-endian byte order.

224-bit unsigned integer represented as little-endian byte order.

232-bit unsigned integer represented as little-endian byte order.

240-bit unsigned integer represented as little-endian byte order.

248-bit unsigned integer represented as little-endian byte order.

256-bit unsigned integer represented as little-endian byte order.

Traits

The addition operator +.

The addition assignment operator +=.

The bitwise AND operator &.

The bitwise AND assignment operator &=.

The bitwise OR operator |.

The bitwise OR assignment operator |=.

The bitwise XOR operator ^.

The bitwise XOR assignment operator ^=.

A data structure that can be deserialized from any data format supported by Serde.

The division operator /.

The division assignment operator /=.

Parse a value from a string

The multiplication operator *.

The multiplication assignment operator *=.

The unary logical negation operator !.

The remainder operator %.

The remainder assignment operator %=.

A data structure that can be serialized into any data format supported by Serde.

The left shift operator <<. Note that because this trait is implemented for all integer types with multiple right-hand-side types, Rust’s type checker has special handling for _ << _, setting the result type for integer operations to the type of the left-hand-side operand. This means that though a << b and a.shl(b) are one and the same from an evaluation standpoint, they are different when it comes to type inference.

The left shift assignment operator <<=.

The right shift operator >>. Note that because this trait is implemented for all integer types with multiple right-hand-side types, Rust’s type checker has special handling for _ >> _, setting the result type for integer operations to the type of the left-hand-side operand. This means that though a >> b and a.shr(b) are one and the same from an evaluation standpoint, they are different when it comes to type inference.

The right shift assignment operator >>=.

The subtraction operator -.

The subtraction assignment operator -=.

Functions

Computes x += y where x and y is a slice. requires: len(x) >= len(y).

Computes 16-bit division of two 8-bit numbers and return the quotient and remainder.

Devides <uh, ul> / d, returns the quotient and remainder. It use provided d’s reciprocal. Implementation is ported from https://github.com/holiman/uint250.

Computes <!d, !0> / d.

Computes x -= y * multiplier. requires: len(x) >= len(y).