1 unstable release
0.1.0 | Sep 22, 2022 |
---|
#399 in #primitive
44KB
1K
SLoC
PRIMITIVES
Ethereum primitives type for rust.
This crate was unstable and maybe lot's of bugs and I suggest not to use this.
Usage
[dependencies]
laron_primitives = "0.1"
use laron_primitives::*;
let x: U256 = 100u128.into();
let y: U256 = 2u128.into();
let z = x * y;
assert_eq!(200u64, z.into());
Macro
To create new type, you can use macro define!
.
use laron_primitives::*;
define!(U512, 64, "512-bits custom type.");
let x: U512 = 100u8.into();
assert_eq!(x * 2u8.into(), 200u8.into());
TODO
- Add Pow/Exp method for each types.
- Add SQRT method for each types.
lib.rs
:
unprim contains primitive types from 8 into 256 bit. it is unstable and not intended for production use.
use laron_primitives::*;
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 laron_primitives::*;
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 laron_primitives::*;
define!(U512, 64, "512 bit");
let a = U512::from(100);
let b = U512::from(2);
let c = a * b;
assert_eq!(c, 200u64.into());
Dependencies
~100–335KB