Skip to content

Commit 989d5c5

Browse files
committed
fix: backport fix from #59
1 parent f060748 commit 989d5c5

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "bytesize"
33
description = "an utility for human-readable bytes representations"
4-
version = "1.3.0"
4+
version = "1.3.1"
55
authors = ["Hyunsik Choi <[email protected]>"]
66

7-
homepage = "https://github.com/hyunsik/bytesize/"
7+
homepage = "https://github.com/bytesize-rs/bytesize/"
88
documentation = "https://docs.rs/bytesize/"
9-
repository = "https://github.com/hyunsik/bytesize/"
9+
repository = "https://github.com/bytesize-rs/bytesize/"
1010
readme = "README.md"
1111
keywords = ["byte", "byte-size", "utility", "human-readable", "format"]
1212
license = "Apache-2.0"

src/lib.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//!
44
//! ## Example
55
//!
6-
//! ```ignore
6+
//! ```no_run
77
//! extern crate bytesize;
88
//!
99
//! use bytesize::ByteSize;
@@ -14,17 +14,15 @@
1414
//!
1515
//! let plus = x + y;
1616
//! print!("{} bytes", plus.as_u64());
17-
//!
18-
//! let minus = ByteSize::tb(100) - ByteSize::gb(4);
19-
//! print!("{} bytes", minus.as_u64());
2017
//! }
2118
//! ```
2219
//!
2320
//! It also provides its human readable string as follows:
2421
//!
25-
//! ```ignore=
26-
//! assert_eq!("482 GiB".to_string(), ByteSize::gb(518).to_string(true));
27-
//! assert_eq!("518 GB".to_string(), ByteSize::gb(518).to_string(false));
22+
//! ```no_run
23+
//! # use bytesize::ByteSize;
24+
//! assert_eq!("482 GiB".to_string(), ByteSize::gb(518).to_string());
25+
//! assert_eq!("518 GB".to_string(), ByteSize::gb(518).to_string());
2826
//! ```
2927
3028
mod parse;
@@ -208,7 +206,7 @@ pub fn to_string(bytes: u64, si_prefix: bool) -> String {
208206
}
209207

210208
impl Display for ByteSize {
211-
fn fmt(&self, f: &mut Formatter) ->fmt::Result {
209+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
212210
f.pad(&to_string(self.0, false))
213211
}
214212
}
@@ -261,7 +259,9 @@ impl AddAssign<ByteSize> for ByteSize {
261259
}
262260

263261
impl<T> Add<T> for ByteSize
264-
where T: Into<u64> {
262+
where
263+
T: Into<u64>,
264+
{
265265
type Output = ByteSize;
266266
#[inline(always)]
267267
fn add(self, rhs: T) -> ByteSize {
@@ -270,15 +270,19 @@ impl<T> Add<T> for ByteSize
270270
}
271271

272272
impl<T> AddAssign<T> for ByteSize
273-
where T: Into<u64> {
273+
where
274+
T: Into<u64>,
275+
{
274276
#[inline(always)]
275277
fn add_assign(&mut self, rhs: T) {
276278
self.0 += rhs.into() as u64;
277279
}
278280
}
279281

280282
impl<T> Mul<T> for ByteSize
281-
where T: Into<u64> {
283+
where
284+
T: Into<u64>,
285+
{
282286
type Output = ByteSize;
283287
#[inline(always)]
284288
fn mul(self, rhs: T) -> ByteSize {
@@ -287,7 +291,9 @@ impl<T> Mul<T> for ByteSize
287291
}
288292

289293
impl<T> MulAssign<T> for ByteSize
290-
where T: Into<u64> {
294+
where
295+
T: Into<u64>,
296+
{
291297
#[inline(always)]
292298
fn mul_assign(&mut self, rhs: T) {
293299
self.0 *= rhs.into() as u64;

src/parse.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ impl std::str::FromStr for ByteSize {
1010
let number = take_while(value, |c| c.is_ascii_digit() || c == '.');
1111
match number.parse::<f64>() {
1212
Ok(v) => {
13-
let suffix = skip_while(value, |c| {
14-
c.is_whitespace() || c.is_ascii_digit() || c == '.'
15-
});
13+
let suffix = skip_while(value, char::is_whitespace);
1614
match suffix.parse::<Unit>() {
1715
Ok(u) => Ok(Self((v * u) as u64)),
1816
Err(error) => Err(format!(
@@ -220,6 +218,9 @@ mod tests {
220218

221219
assert!(parse("").is_err());
222220
assert!(parse("a124GB").is_err());
221+
assert!(parse("1.3 42.0 B").is_err());
222+
assert!(parse("1.3 ... B").is_err());
223+
assert!(parse("1 000 B").is_err());
223224
}
224225

225226
#[test]

0 commit comments

Comments
 (0)