Numbers for Rust
LinksPlatform's platform-num crate — numeric traits and types
for the Links platform.
Crates.io package: platform-num
Overview
This crate provides a set of numeric traits used throughout the LinksPlatform ecosystem:
Num— A base trait combiningPrimInt,Default,Debug,AsPrimitive<usize>, andToPrimitive. Implemented for all primitive integer types.SignNum— ExtendsNumwith signed number operations (Signed,FromPrimitive). Implemented for signed integer types.ToSigned— Converts unsigned types to their signed counterparts (e.g.u32→i32).MaxValue— Provides aMAXassociated constant for all primitive integer types.LinkType— A composite trait for types that can be used as link identifiers:Num + Unsigned + ToSigned + MaxValue + FromPrimitive + Debug + Display + Hash + Send + Sync + 'static. Implemented foru8,u16,u32,u64, andusize.
Installation
Add to your Cargo.toml:
[]
= "0.2"
Usage
Using LinkType as a generic constraint
use LinkType;
let link = create_link;
assert_eq!;
Using ToSigned for type conversion
use ToSigned;
let unsigned_val: u32 = 42;
let signed_val: i32 = unsigned_val.to_signed;
assert_eq!;
Using MaxValue
use MaxValue;
assert_eq!;
Using Num for generic numeric operations
use Num;
use AsPrimitive;
assert_eq!;
Depend on
Dependent libraries
License
This crate is released to the public domain under the Unlicense.
The Unlicense is the most permissive license available — it places no restrictions whatsoever on users. You are free to copy, modify, publish, use, compile, sell, or distribute this software for any purpose, commercial or non-commercial, in any way you choose, with no conditions attached.
Unlike LGPL, which forces users to redistribute modifications under the same license and comply with specific obligations (linking restrictions, source disclosure for modifications), the Unlicense imposes no obligations at all. It is truly free as in freedom.