Crates.io | bytelike |
lib.rs | bytelike |
version | |
source | src |
created_at | 2024-11-15 03:01:52.40267 |
updated_at | 2025-01-30 19:54:26.044887 |
description | Common types and functions for byte size handling |
homepage | |
repository | |
max_upload_size | |
id | 1448567 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
ByteLike is a procedural macro crate for deriving ByteLike
functions for deriving byte-like new types.
It's a procedural macro that was created based off the implementation of ByteSize.
Add this to your Cargo.toml
[dependencies]
bytelike = { version = "0.1", features = ["serde"] }
Or if don't want serde:
[dependencies]
bytelike = { version = "0.1" }
Note, you can also disable std:
[dependencies]
bytelike = { version = "0.1", no-default-features = true }
Next, define your new type and derive ByteLike
for it:
use bytelike_derive::ByteLike;
#[derive(ByteLike)]
pub struct NewType(pub u64);
Now you can do lots of useful byte-like things with your new type:
let new_type_a: NewType = "5KiB".parse().unwrap();
let new_type_b: NewType = NewType::kib(5);
let sum = new_type + other_type;
let sum = new_type + 5;
See the documentation for ByteSize to see more examples of what you can do with the ByteLike new type (just replace ByteSize with your new type name).
In addition, if you only want some of the ByteLike functions derived, you can use any of the following derives in an additive manner:
serde
feature)