humanbyte-derive 0.2.0

A procedural macro for deriving human readable byte functions
Documentation
  • Coverage
  • 0%
    0 out of 8 items documented0 out of 7 items with examples
  • Size
  • Source code size: 17.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 327.51 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lthiery

HumanByte-Derive

Build Status Crates.io Version

HumanByte Derive is a procedural macro crate for deriving HumanByte functions for deriving byte-like new types.

Usage

Add this to your Cargo.toml:

With serde support

[dependencies]
humanbyte = { version = "0.1" }
humanbyte-derive = { version = "0.1", features = ["serde"] }

Without serde support

[dependencies]
humanbyte = { version = "0.1" }
humanbyte-derive = { version = "0.1" }

Next, define your new type and derive HumanByte for it:

use humanbyte_derive::HumanByte;

#[derive(HumanByte)]
pub struct ByteSize(u64);

This will derive all the necessary functions for your new type. You can then use it like this:

let size = ByteSize::mb(1);
assert_eq!(size.to_string(), "1.0 MB");

See the documentation for ByteSize to see more examples of what you can do with the HumanByte new type (just replace ByteSize with your own type name).

In addition, if you only want some of the HumanByte functions derived, you can use any of the following derives in an a la carte fashion:

  • HumanByteConstructor
  • HumanByteDisplay
  • HumanByteParse
  • HumanByteOps
  • HumanByteFromStr
  • HumanByteSerde (requires the serde feature)