#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

28 releases (16 breaking)

new 0.26.0 Jan 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

#760 in Rust patterns

Download history 1259/week @ 2024-09-17 1794/week @ 2024-09-24 1434/week @ 2024-10-01 852/week @ 2024-10-08 957/week @ 2024-10-15 1276/week @ 2024-10-22 1892/week @ 2024-10-29 1478/week @ 2024-11-05 1712/week @ 2024-11-12 2135/week @ 2024-11-19 2144/week @ 2024-11-26 2035/week @ 2024-12-03 2711/week @ 2024-12-10 1896/week @ 2024-12-17 752/week @ 2024-12-24 906/week @ 2024-12-31

6,608 downloads per month
Used in 56 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