#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

29 releases (17 breaking)

new 0.27.0 Feb 7, 2025
0.25.0 Dec 2, 2024
0.24.0 Oct 31, 2024
0.20.0 Jun 27, 2024
0.0.0 Jun 24, 2021

#1820 in Rust patterns

Download history 1148/week @ 2024-10-19 1213/week @ 2024-10-26 2192/week @ 2024-11-02 1223/week @ 2024-11-09 2427/week @ 2024-11-16 1764/week @ 2024-11-23 2298/week @ 2024-11-30 2563/week @ 2024-12-07 2387/week @ 2024-12-14 775/week @ 2024-12-21 926/week @ 2024-12-28 1562/week @ 2025-01-04 1789/week @ 2025-01-11 1328/week @ 2025-01-18 1395/week @ 2025-01-25 846/week @ 2025-02-01

5,594 downloads per month
Used in 55 crates (9 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–9.5MB
~93K SLoC