#tor #safe-wrapper #arti #numeric #range #integer #type

tor-units

Provides macros for types which are constrained within a range, ensuring invalid values are unrepresentable

26 releases (14 breaking)

0.24.0 Oct 31, 2024
0.22.0 Sep 3, 2024
0.20.0 Jun 27, 2024
0.6.5 Mar 4, 2024
0.0.0 Jun 24, 2021

#737 in Rust patterns

Download history 709/week @ 2024-07-19 1115/week @ 2024-07-26 1546/week @ 2024-08-02 1309/week @ 2024-08-09 1182/week @ 2024-08-16 1531/week @ 2024-08-23 1626/week @ 2024-08-30 1753/week @ 2024-09-06 1178/week @ 2024-09-13 1294/week @ 2024-09-20 1796/week @ 2024-09-27 1128/week @ 2024-10-04 974/week @ 2024-10-11 1144/week @ 2024-10-18 1094/week @ 2024-10-25 2064/week @ 2024-11-01

5,381 downloads per month
Used in 49 crates (8 directly)

MIT/Apache

88KB
1.5K SLoC

tor-units

Safe wrappers for primitive numeric types.

Overview

This crate is part of Arti, a project to implement Tor in Rust. It provides safe wrappers for primitive numeric wrappers used in other parts of Arti. In particular, it provides:

  • a bounded i32 with both checked and clamping constructors,
  • an integer milliseconds wrapper with conversion to Duration
  • an integer seconds wrapper with conversion to Duration
  • a percentage wrapper, to prevent accidental failure to divide by 100.
  • a SendMeVersion which can be compared only.

Compile-time features

  • memquota-memcost -- implement tor_memquota::HasMemoryCost for many types. (Does not actually force compiling in memory quota tracking; that's memquota in tor-memquota and higher-level crates.)

  • full -- Enable all features above.

License: MIT OR Apache-2.0


lib.rs:

Dependencies

~0.3–10MB
~99K SLoC