#memory-size #size #memory #datatype #type

no-std memory-size-type

A data type for dealing with memory sizes

7 releases (4 breaking)

0.5.0 Jan 2, 2022
0.4.1 Oct 10, 2021
0.3.0 Oct 8, 2021
0.2.0 Oct 5, 2021
0.1.1 Oct 4, 2021

#1780 in Rust patterns

Download history 4/week @ 2024-02-23 2/week @ 2024-03-01 4/week @ 2024-03-08 1/week @ 2024-03-15 53/week @ 2024-03-29

58 downloads per month

MIT license

12KB
74 lines

MemorySize Type

Build MIT License API docs crates.io

This crate provides the MemorySize data type as a size unit. This might help errors during conversion between different units as well as comfort for printing the managed size as a human-readable value.

Usage

To use this library, you just have to add the following lines into your projects Cargo.toml:

[dependencies.memory-size-type]
version = "0.5.0"
default-features = false
features = ["std"]

Features

The crate is seperated into several features to reduce its size (even with this small crate). You can use the following features to enable the stuff you really need in your project:

Feature Description
std Include features like implementations for std::fmt::Debug and std::fmt::Display
deprecated Include the deprecated features like the MemorySize type.

Examples

There are different use-cases for this library. The following examples represent just some possible usages.

Creating an instance from raw byte information

use memory_size_type::Byte;

let size_info_byte = Byte::from(1024);

Calculating with memory sizes

use memory_size_type::Byte;

let some_bytes = Byte::from(1024);
let some_more_bytes = Byte::from(1024);

assert_eq!(some_bytes + some_more_bytes, 2048);

No runtime deps

Features