From 92f5db775a511c2e365856651fc0e29e1dca725e Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Wed, 23 Aug 2023 16:00:42 -0500 Subject: [PATCH 1/6] Bump up the version to 1.3.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f714197..33cfaf2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bytesize" description = "an utility for human-readable bytes representations" -version = "1.3.0-dev" +version = "1.3.0" authors = ["Hyunsik Choi "] homepage = "https://github.com/hyunsik/bytesize/" From f0607486402472bb36a5fc395b3dd79520b29d62 Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Wed, 23 Aug 2023 16:04:26 -0500 Subject: [PATCH 2/6] Bump up the dependency versions --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 33cfaf2..46c6c54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,12 +12,12 @@ keywords = ["byte", "byte-size", "utility", "human-readable", "format"] license = "Apache-2.0" [dependencies] -serde = { version = "1.0", optional = true } +serde = { version = "1.0.185", optional = true } [dev-dependencies] -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -toml = "0.5" +serde = { version = "1.0.185", features = ["derive"] } +serde_json = "1.0.105" +toml = "0.7.6" [features] default = [] From 989d5c5e0aff6da21b853e38226dff8b6441a342 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 9 Feb 2025 23:33:55 +0000 Subject: [PATCH 3/6] fix: backport fix from #59 --- Cargo.toml | 6 +++--- src/lib.rs | 30 ++++++++++++++++++------------ src/parse.rs | 7 ++++--- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 46c6c54..4c1fd65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "bytesize" description = "an utility for human-readable bytes representations" -version = "1.3.0" +version = "1.3.1" authors = ["Hyunsik Choi "] -homepage = "https://github.com/hyunsik/bytesize/" +homepage = "https://github.com/bytesize-rs/bytesize/" documentation = "https://docs.rs/bytesize/" -repository = "https://github.com/hyunsik/bytesize/" +repository = "https://github.com/bytesize-rs/bytesize/" readme = "README.md" keywords = ["byte", "byte-size", "utility", "human-readable", "format"] license = "Apache-2.0" diff --git a/src/lib.rs b/src/lib.rs index 01c4440..25db65b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ //! //! ## Example //! -//! ```ignore +//! ```no_run //! extern crate bytesize; //! //! use bytesize::ByteSize; @@ -14,17 +14,15 @@ //! //! let plus = x + y; //! print!("{} bytes", plus.as_u64()); -//! -//! let minus = ByteSize::tb(100) - ByteSize::gb(4); -//! print!("{} bytes", minus.as_u64()); //! } //! ``` //! //! It also provides its human readable string as follows: //! -//! ```ignore= -//! assert_eq!("482 GiB".to_string(), ByteSize::gb(518).to_string(true)); -//! assert_eq!("518 GB".to_string(), ByteSize::gb(518).to_string(false)); +//! ```no_run +//! # use bytesize::ByteSize; +//! assert_eq!("482 GiB".to_string(), ByteSize::gb(518).to_string()); +//! assert_eq!("518 GB".to_string(), ByteSize::gb(518).to_string()); //! ``` mod parse; @@ -208,7 +206,7 @@ pub fn to_string(bytes: u64, si_prefix: bool) -> String { } impl Display for ByteSize { - fn fmt(&self, f: &mut Formatter) ->fmt::Result { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.pad(&to_string(self.0, false)) } } @@ -261,7 +259,9 @@ impl AddAssign for ByteSize { } impl Add for ByteSize - where T: Into { +where + T: Into, +{ type Output = ByteSize; #[inline(always)] fn add(self, rhs: T) -> ByteSize { @@ -270,7 +270,9 @@ impl Add for ByteSize } impl AddAssign for ByteSize - where T: Into { +where + T: Into, +{ #[inline(always)] fn add_assign(&mut self, rhs: T) { self.0 += rhs.into() as u64; @@ -278,7 +280,9 @@ impl AddAssign for ByteSize } impl Mul for ByteSize - where T: Into { +where + T: Into, +{ type Output = ByteSize; #[inline(always)] fn mul(self, rhs: T) -> ByteSize { @@ -287,7 +291,9 @@ impl Mul for ByteSize } impl MulAssign for ByteSize - where T: Into { +where + T: Into, +{ #[inline(always)] fn mul_assign(&mut self, rhs: T) { self.0 *= rhs.into() as u64; diff --git a/src/parse.rs b/src/parse.rs index a5cca5b..0f5aa60 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -10,9 +10,7 @@ impl std::str::FromStr for ByteSize { let number = take_while(value, |c| c.is_ascii_digit() || c == '.'); match number.parse::() { Ok(v) => { - let suffix = skip_while(value, |c| { - c.is_whitespace() || c.is_ascii_digit() || c == '.' - }); + let suffix = skip_while(value, char::is_whitespace); match suffix.parse::() { Ok(u) => Ok(Self((v * u) as u64)), Err(error) => Err(format!( @@ -220,6 +218,9 @@ mod tests { assert!(parse("").is_err()); assert!(parse("a124GB").is_err()); + assert!(parse("1.3 42.0 B").is_err()); + assert!(parse("1.3 ... B").is_err()); + assert!(parse("1 000 B").is_err()); } #[test] From 855e1e882ec9c33f1a9954667edc609857f44f4d Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 11 Feb 2025 03:48:49 +0000 Subject: [PATCH 4/6] fix: correct parsing of units --- src/parse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse.rs b/src/parse.rs index 0f5aa60..6296fe3 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -10,7 +10,7 @@ impl std::str::FromStr for ByteSize { let number = take_while(value, |c| c.is_ascii_digit() || c == '.'); match number.parse::() { Ok(v) => { - let suffix = skip_while(value, char::is_whitespace); + let suffix = skip_while(&value[number.len()..], char::is_whitespace); match suffix.parse::() { Ok(u) => Ok(Self((v * u) as u64)), Err(error) => Err(format!( From 110336a41ec2393737455cc4208cf7c2e7a0f7c2 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 11 Feb 2025 03:49:07 +0000 Subject: [PATCH 5/6] chore: prepare release v1.3.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4c1fd65..47d6957 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bytesize" description = "an utility for human-readable bytes representations" -version = "1.3.1" +version = "1.3.2" authors = ["Hyunsik Choi "] homepage = "https://github.com/bytesize-rs/bytesize/" From 603a713824b907dabcd3c0ed218757d91ce85c9d Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 31 Mar 2025 07:25:41 +0100 Subject: [PATCH 6/6] chore: prepare release v1.3.3 --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 47d6957..85efc35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bytesize" description = "an utility for human-readable bytes representations" -version = "1.3.2" +version = "1.3.3" authors = ["Hyunsik Choi "] homepage = "https://github.com/bytesize-rs/bytesize/" @@ -10,6 +10,7 @@ repository = "https://github.com/bytesize-rs/bytesize/" readme = "README.md" keywords = ["byte", "byte-size", "utility", "human-readable", "format"] license = "Apache-2.0" +rust-version = "1.61" [dependencies] serde = { version = "1.0.185", optional = true }