Crates.io | arranged |
lib.rs | arranged |
version | 0.1.2 |
source | src |
created_at | 2022-04-16 11:31:46.845329 |
updated_at | 2022-04-17 15:33:07.100527 |
description | Statically bounds-checked (machine-word-abstracting? TBD) ranged types as zero or low-runtime overhead abstractions providing safe (no unintentional overflow) arithmetic. |
homepage | |
repository | https://github.com/u007d/arranged |
max_upload_size | |
id | 568938 |
size | 159,149 |
A Rust ranged-type library.
arranged
is ranged type crate for Rust. Note: This crate is currently pre-alpha and is still under construction.
arranged
is a pathfinder implementation to safe default arithmetic manipulation of values in Rust--no arithmetic operation should ever fail (panic) due to overflow at runtime
(unless the user explicitly requests a panic)--while supporting ergonomics via conventional arithmetic operators (+
, -
, *
, /
, %
, etc.).
The Ranged type is designed to be zero-runtime overhead where possible and minimal runtime overhead otherwise:
mem::size_of::<Ranged<T>>() == mem::size_of::<T>()
(i.e. ranges are zero-sized). Performance & cache-friendly, esp. when
operating on large quantities of valuesRanged<T>
{op} Ranged<U>
yields Range<V>
and is compile-time bounds checked (where {op} represents an arithmetic
operation, and T
, U
and V
represent Ranges of values of the same machine word type). Any possible overflow fails to compile.Ranged<T>
{op} *Wrapper<Ranged<U>>
yields Ranged<T>
, is runtime bounds-checked and handles overflow according to*
policy, where *
is one of Checked, Overflowing, Panicking, Saturating or Wrapping overflow policies.Ranged<T>
{op} {scalar} does not compile because policy is unspecifiedRanged<T>
{op} *Wrapper<{scalar}>
yields Ranged<T>
, is runtime bounds-checked and handles overflow according to*
policyRanged<T>
does not compile because policy is unspecified*Wrapper<{scalar}>
yields *Wrapper<{scalar}>
, is runtime bounds-checked and handles overflow according to *
policy*Wrapper<Ranged<T>>
yields *Wrapper<Ranged<T>>
, is runtime bounds-checked and handles overflow according to *
policy*Wrapper<Ranged<T>>
{op} Ranged<U>
yields *Wrapper<Ranged<V>>
, is compile-time bounds checked and handles overflow according to *
policy*Wrapper<Ranged<T>>
{op} †Wrapper<Ranged<U>>
yields *Wrapper<Ranged<T>>
, is runtime bounds checked and handles overflow according to *
policy. †
policy is ignored.*Wrapper<Ranged<T>
{op} {scalar} yields *Wrapper<"Ranged<T>>
, is runtime bounds checked and handles overflow according to *
policy.Panicking
policy (arith_traits)— !! pathfinder complete !! — if successful:
Ranged<Ri*>
(where Ri
is arranged
’s range-inclusive type and *
represents any int and float machine word types or BigInt
or BigUint
)Ranged<R*>
(where R
is arranged
’s (half-open) range type and *
represents any int and float machine word types or BigInt
or BigUint
)arranged
addressing?Rust has made terrific progress moving the safety and correctness needle without sacrificing performance. And yet we are still saddled with C’s arithmetic model from the early 1970's which does a very poor job of providing predictable behavior in important real-world safety scenarios--Ariane 5 initial launch, analysis.
As software eats more and more of the world, the importance of performant, ergonomic, ‘safe by default’ systems increases.
Explore leveraging arranged as part of a more comprehensive “semantic types” implementation in Rust, hopefully further addressing safety concerns such as NASA losing a $300M+ mission
// Create a `u8`-based `RangeInclusive`-style type limited to `1..=100`, set to the value 42
let my_ranged_value = Ranged::<RiU8<1, 100>>::from(42);
For more examples, see ranged::unit_tests
.
Licensed under either:
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.