diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/bytesize | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/bytesize')
-rw-r--r-- | vendor/bytesize/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/bytesize/Cargo.toml | 10 | ||||
-rw-r--r-- | vendor/bytesize/README.md | 3 | ||||
-rw-r--r-- | vendor/bytesize/src/parse.rs | 36 |
4 files changed, 36 insertions, 15 deletions
diff --git a/vendor/bytesize/.cargo-checksum.json b/vendor/bytesize/.cargo-checksum.json index c8c9e3f95..7777d26b8 100644 --- a/vendor/bytesize/.cargo-checksum.json +++ b/vendor/bytesize/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"edf0f31ce8a53b46c1fa632fded9f6a9bd94c75505fec7470e02c9e7afb60679","LICENSE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","README.md":"d0deb99fef48f13ec4439888a677c4f2c46cc92ba35eebf8cf53ded962852c7f","src/lib.rs":"f6c4d6e4788dba33a992750947f72999b3e0b418bfa3f425229e60fe35952ffc","src/parse.rs":"7b8287d5cda2b7e001c8deb8eee68d8e5b9753d0cfd30ccec480382a1eebf0de"},"package":"38fcc2979eff34a4b84e1cf9a1e3da42a7d44b3b690a40cdcb23e3d556cfb2e5"}
\ No newline at end of file +{"files":{"Cargo.toml":"635bcf320cd6157cab9e248bf2aa0c7bfd5424fc61a31cdc2b03c19637a051a9","LICENSE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","README.md":"2b9d71747b678d87044d2679e577ca5cee84db771cc955d25f8e897a08cd7f45","src/lib.rs":"f6c4d6e4788dba33a992750947f72999b3e0b418bfa3f425229e60fe35952ffc","src/parse.rs":"6682ec95bc91a3e972b1ccbb6a32add5c96a0ad542253c2a4ebe64d3e24b3f32"},"package":"a3e368af43e418a04d52505cf3dbc23dda4e3407ae2fa99fd0e4f308ce546acc"}
\ No newline at end of file diff --git a/vendor/bytesize/Cargo.toml b/vendor/bytesize/Cargo.toml index 475fef195..316fc7c36 100644 --- a/vendor/bytesize/Cargo.toml +++ b/vendor/bytesize/Cargo.toml @@ -11,7 +11,7 @@ [package] name = "bytesize" -version = "1.2.0" +version = "1.3.0" authors = ["Hyunsik Choi <hyunsik.choi@gmail.com>"] description = "an utility for human-readable bytes representations" homepage = "https://github.com/hyunsik/bytesize/" @@ -28,18 +28,18 @@ license = "Apache-2.0" repository = "https://github.com/hyunsik/bytesize/" [dependencies.serde] -version = "1.0" +version = "1.0.185" optional = true [dev-dependencies.serde] -version = "1.0" +version = "1.0.185" features = ["derive"] [dev-dependencies.serde_json] -version = "1.0" +version = "1.0.105" [dev-dependencies.toml] -version = "0.5" +version = "0.7.6" [features] default = [] diff --git a/vendor/bytesize/README.md b/vendor/bytesize/README.md index 3db9c8307..b25bc9dd5 100644 --- a/vendor/bytesize/README.md +++ b/vendor/bytesize/README.md @@ -10,6 +10,7 @@ Features: * `ByteSize` type which presents size units convertible to different size units. * Artimetic operations for `ByteSize` * FromStr impl for `ByteSize`, allowing to parse from string size representations like 1.5KiB and 521TiB. +* Serde support for binary and human-readable deserializers like JSON [API Documentation](https://docs.rs/bytesize/) @@ -19,7 +20,7 @@ Add this to your Cargo.toml: ```toml [dependencies] -bytesize = {version = "1.1.0", features = ["serde"]} +bytesize = {version = "1.2.0", features = ["serde"]} ``` and this to your crate root: diff --git a/vendor/bytesize/src/parse.rs b/vendor/bytesize/src/parse.rs index e86034e2f..a5cca5b3d 100644 --- a/vendor/bytesize/src/parse.rs +++ b/vendor/bytesize/src/parse.rs @@ -7,16 +7,12 @@ impl std::str::FromStr for ByteSize { if let Ok(v) = value.parse::<u64>() { return Ok(Self(v)); } - let number: String = value - .chars() - .take_while(|c| c.is_ascii_digit() || c == &'.') - .collect(); + let number = take_while(value, |c| c.is_ascii_digit() || c == '.'); match number.parse::<f64>() { Ok(v) => { - let suffix: String = value - .chars() - .skip_while(|c| c.is_whitespace() || c.is_ascii_digit() || c == &'.') - .collect(); + let suffix = skip_while(value, |c| { + c.is_whitespace() || c.is_ascii_digit() || c == '.' + }); match suffix.parse::<Unit>() { Ok(u) => Ok(Self((v * u) as u64)), Err(error) => Err(format!( @@ -33,6 +29,30 @@ impl std::str::FromStr for ByteSize { } } +fn take_while<P>(s: &str, mut predicate: P) -> &str +where + P: FnMut(char) -> bool, +{ + let offset = s + .chars() + .take_while(|ch| predicate(*ch)) + .map(|ch| ch.len_utf8()) + .sum(); + &s[..offset] +} + +fn skip_while<P>(s: &str, mut predicate: P) -> &str +where + P: FnMut(char) -> bool, +{ + let offset: usize = s + .chars() + .skip_while(|ch| predicate(*ch)) + .map(|ch| ch.len_utf8()) + .sum(); + &s[(s.len() - offset)..] +} + enum Unit { Byte, // power of tens |