sizefilter
Human-readable size string parsing, formatting, arithmetic, and filtering with comparison operators.
Overview
sizefilter provides human-readable size string parsing, formatting, arithmetic, and filtering with comparison operators. It supports binary units (1 KB = 1024 B) matching filesystem conventions, with zero heap allocation in parsing and error paths. The library offers comprehensive support for sizes from bytes to exabytes with intuitive string representations.
Why sizefilter?
Unlike other size parsing libraries that only handle basic conversions, sizefilter provides a complete solution for working with human-readable sizes in Rust. It supports comparison operators (>=1GB, <500KB, =0), arithmetic operations, and seamless integration with serde for configuration files. The library's use of i64 (not u64) allows for negative sizes, and its zero-allocation design makes it suitable for performance-critical applications. For tools that need to parse, compare, or manipulate file sizes from user input, sizefilter offers the most ergonomic and complete solution.
Usage
Add to your Cargo.toml:
[]
= "0.2.0"
Quick start
use *;
// Parse a human-readable size to bytes
let bytes = parse_size.unwrap;
assert_eq!;
// Using the Size newtype
let s: Size = "2GB".parse.unwrap;
assert_eq!;
assert_eq!;
// Parse a filter expression
let f: SizeFilter = ">=500MB".parse.unwrap;
assert!;
assert!;
// Use convenience constructors
let f = lt;
assert!;
// Arithmetic
assert_eq!;