#tor #range #value #milliseconds #integer #numeric #tor-arti #percentage #i32 #bounded

tor-units

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

34 releases (22 breaking)

new 0.32.0 Jul 8, 2025
0.30.0 May 1, 2025
0.28.0 Mar 3, 2025
0.25.0 Dec 2, 2024
0.0.0 Jun 24, 2021

#284 in Rust patterns

Download history 1113/week @ 2025-03-18 946/week @ 2025-03-25 1456/week @ 2025-04-01 942/week @ 2025-04-08 2411/week @ 2025-04-15 2405/week @ 2025-04-22 1514/week @ 2025-04-29 2098/week @ 2025-05-06 3067/week @ 2025-05-13 5479/week @ 2025-05-20 3207/week @ 2025-05-27 4084/week @ 2025-06-03 3787/week @ 2025-06-10 1884/week @ 2025-06-17 2576/week @ 2025-06-24 3540/week @ 2025-07-01

12,134 downloads per month
Used in 67 crates (8 directly)

MIT/Apache

89KB
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

Dependencies

~0.4–10MB
~102K SLoC