memory_size

Crates.iomemory_size
lib.rsmemory_size
version0.1.2
created_at2025-04-15 15:56:56.093276+00
updated_at2025-09-07 21:38:22.959323+00
descriptionA crate with the ability to represent a number of bits or bytes, and apply arithmetic to the sizes
homepage
repositoryhttps://github.com/trauts1234/MemorySize
max_upload_size
id1634713
size18,588
(trauts1234)

documentation

README

Memory Size

MemorySize is a Rust library for representing a number of bits or bytes. It provides utilities for working with memory sizes in bytes and bits, as well as performing arithmetic operations, comparisons, and formatting.

Features

  • Create memory sizes from bytes or bits.
  • Perform arithmetic operations (+, -, +=, -=) on memory sizes.
  • Compare memory sizes using PartialOrd and Ord.
  • Pretty-print memory sizes in human-readable formats (e.g. 10 kB, 1 GB).
  • Clamp, find the maximum, or find the minimum of memory sizes.
  • Sum memory sizes from iterators.
  • Align memory offsets

Example

use memory_size::MemorySize;

fn main() {
    let size1 = MemorySize::from_bytes(1024); // 1 KB
    let size2 = MemorySize::from_bytes(2048); // 2 KB

    let total = size1 + size2;
    println!("Total size: {}", total); // Output: Total size: 3 kB
}

Testing

To run the testing scripts, use:

cargo test
Commit count: 26

cargo fmt