Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All significant changes to this software be documented in this file.

## Unreleased

### Bug fixes

* Parse arbitrarily precise fractional byte sizes without double rounding or false overflow.

## v0.3.0 (2026-06-28)

### Breaking changes
Expand Down
49 changes: 49 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions bsize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ macroweave = "0.1.0"
serde_core = { version = "1", default-features = false, optional = true }

[dev-dependencies]
divan = "0.1.21"
insta = { version = "1.47.2" }
quickcheck = { version = "1.0.0" }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = { version = "1.0.150" }
toml = { version = "1.1.2" }

[[bench]]
harness = false
name = "parse"

[lints]
workspace = true
59 changes: 59 additions & 0 deletions bsize/benches/parse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2026 FastLabs Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use bsize::BSize64;
use bsize::ParseError;

#[derive(Clone, Copy)]
struct ParseCase {
name: &'static str,
input: &'static str,
}

impl fmt::Display for ParseCase {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.name)
}
}

const fn case(name: &'static str, input: &'static str) -> ParseCase {
ParseCase { name, input }
}

const CASES: [ParseCase; 10] = [
case("plain", "42"),
case("decimal-unit", "42 MB"),
case("binary-unit", "1 KiB"),
case("fraction", "1.5 MiB"),
case("small-fraction", "0.0025 KB"),
case("grouped", "1_234_567_890"),
case("u64-max", "18_446_744_073_709_551_615"),
case("high-precision-decimal", "1.84467440737095516145 EB"),
case(
"high-precision-binary",
"0.0000000000000000004336808689942017736029811203479766845703125 EiB",
),
case("malformed", "not-a-size"),
];

fn main() {
divan::main();
}

#[divan::bench(args = CASES, sample_size = 1024)]
fn parse(case: ParseCase) -> Result<BSize64, ParseError> {
divan::black_box(case.input).parse()
}
Loading