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

tor-units

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

30 releases (18 breaking)

0.28.0 Mar 3, 2025
0.26.0 Jan 7, 2025
0.25.0 Dec 2, 2024
0.24.0 Oct 31, 2024
0.0.0 Jun 24, 2021

#321 in Rust patterns

Download history 1687/week @ 2024-11-21 2345/week @ 2024-11-28 2324/week @ 2024-12-05 2384/week @ 2024-12-12 1450/week @ 2024-12-19 815/week @ 2024-12-26 1384/week @ 2025-01-02 1413/week @ 2025-01-09 1802/week @ 2025-01-16 1451/week @ 2025-01-23 959/week @ 2025-01-30 3341/week @ 2025-02-06 1470/week @ 2025-02-13 1299/week @ 2025-02-20 1600/week @ 2025-02-27 1148/week @ 2025-03-06

5,722 downloads per month
Used in 56 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


lib.rs:

Dependencies

~0.3–10MB
~98K SLoC