| { | ||
| "git": { | ||
| "sha1": "38f41b6e170c432e88d684ebd6b546e4ca837ebf" | ||
| "sha1": "196823aa3a859324cca61b61e7aafa4c98988f1a" | ||
| }, | ||
| "path_in_vcs": "utils/writeable" | ||
| } |
+54
-56
@@ -11,3 +11,3 @@ # This file is automatically @generated by Cargo. | ||
| dependencies = [ | ||
| "hermit-abi", | ||
| "hermit-abi 0.1.19", | ||
| "libc", | ||
@@ -43,5 +43,5 @@ "winapi", | ||
| name = "bumpalo" | ||
| version = "3.11.0" | ||
| version = "3.12.0" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" | ||
| checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" | ||
@@ -130,5 +130,5 @@ [[package]] | ||
| name = "crossbeam-epoch" | ||
| version = "0.9.10" | ||
| version = "0.9.13" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" | ||
| checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" | ||
| dependencies = [ | ||
@@ -139,3 +139,2 @@ "autocfg", | ||
| "memoffset", | ||
| "once_cell", | ||
| "scopeguard", | ||
@@ -146,8 +145,7 @@ ] | ||
| name = "crossbeam-utils" | ||
| version = "0.8.11" | ||
| version = "0.8.14" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" | ||
| checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" | ||
| dependencies = [ | ||
| "cfg-if", | ||
| "once_cell", | ||
| ] | ||
@@ -185,5 +183,5 @@ | ||
| name = "getrandom" | ||
| version = "0.2.7" | ||
| version = "0.2.8" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" | ||
| checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" | ||
| dependencies = [ | ||
@@ -211,6 +209,9 @@ "cfg-if", | ||
| [[package]] | ||
| name = "icu_benchmark_macros" | ||
| version = "0.7.0" | ||
| name = "hermit-abi" | ||
| version = "0.2.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "6c867656f2d9c90b13709ac88e710a9d6afe33998c1dfa22384bab8804e8b3d4" | ||
| checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" | ||
| dependencies = [ | ||
| "libc", | ||
| ] | ||
@@ -234,5 +235,5 @@ [[package]] | ||
| name = "itoa" | ||
| version = "1.0.3" | ||
| version = "1.0.5" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" | ||
| checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" | ||
@@ -256,5 +257,5 @@ [[package]] | ||
| name = "libc" | ||
| version = "0.2.133" | ||
| version = "0.2.139" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" | ||
| checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" | ||
@@ -278,5 +279,5 @@ [[package]] | ||
| name = "memoffset" | ||
| version = "0.6.5" | ||
| version = "0.7.1" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" | ||
| checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" | ||
| dependencies = [ | ||
@@ -297,7 +298,7 @@ "autocfg", | ||
| name = "num_cpus" | ||
| version = "1.13.1" | ||
| version = "1.15.0" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" | ||
| checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" | ||
| dependencies = [ | ||
| "hermit-abi", | ||
| "hermit-abi 0.2.6", | ||
| "libc", | ||
@@ -308,5 +309,5 @@ ] | ||
| name = "once_cell" | ||
| version = "1.15.0" | ||
| version = "1.17.0" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" | ||
| checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" | ||
@@ -349,11 +350,11 @@ [[package]] | ||
| name = "ppv-lite86" | ||
| version = "0.2.16" | ||
| version = "0.2.17" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" | ||
| checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" | ||
| [[package]] | ||
| name = "proc-macro2" | ||
| version = "1.0.44" | ||
| version = "1.0.50" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "7bd7356a8122b6c4a24a82b278680c73357984ca2fc79a0f9fa6dea7dced7c58" | ||
| checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" | ||
| dependencies = [ | ||
@@ -365,5 +366,5 @@ "unicode-ident", | ||
| name = "quote" | ||
| version = "1.0.21" | ||
| version = "1.0.23" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" | ||
| checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" | ||
| dependencies = [ | ||
@@ -405,8 +406,6 @@ "proc-macro2", | ||
| name = "rayon" | ||
| version = "1.5.3" | ||
| version = "1.6.1" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" | ||
| checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" | ||
| dependencies = [ | ||
| "autocfg", | ||
| "crossbeam-deque", | ||
| "either", | ||
@@ -418,5 +417,5 @@ "rayon-core", | ||
| name = "rayon-core" | ||
| version = "1.9.3" | ||
| version = "1.10.2" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" | ||
| checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" | ||
| dependencies = [ | ||
@@ -431,5 +430,5 @@ "crossbeam-channel", | ||
| name = "regex" | ||
| version = "1.6.0" | ||
| version = "1.7.1" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" | ||
| checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" | ||
| dependencies = [ | ||
@@ -447,11 +446,11 @@ "regex-syntax", | ||
| name = "regex-syntax" | ||
| version = "0.6.27" | ||
| version = "0.6.28" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" | ||
| checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" | ||
| [[package]] | ||
| name = "ryu" | ||
| version = "1.0.11" | ||
| version = "1.0.12" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" | ||
| checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" | ||
@@ -475,5 +474,5 @@ [[package]] | ||
| name = "serde" | ||
| version = "1.0.145" | ||
| version = "1.0.152" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" | ||
| checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" | ||
@@ -492,5 +491,5 @@ [[package]] | ||
| name = "serde_derive" | ||
| version = "1.0.145" | ||
| version = "1.0.152" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" | ||
| checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" | ||
| dependencies = [ | ||
@@ -504,7 +503,7 @@ "proc-macro2", | ||
| name = "serde_json" | ||
| version = "1.0.85" | ||
| version = "1.0.91" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" | ||
| checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" | ||
| dependencies = [ | ||
| "itoa 1.0.3", | ||
| "itoa 1.0.5", | ||
| "ryu", | ||
@@ -516,5 +515,5 @@ "serde", | ||
| name = "syn" | ||
| version = "1.0.101" | ||
| version = "1.0.107" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" | ||
| checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" | ||
| dependencies = [ | ||
@@ -547,5 +546,5 @@ "proc-macro2", | ||
| name = "unicode-ident" | ||
| version = "1.0.4" | ||
| version = "1.0.6" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" | ||
| checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" | ||
@@ -672,7 +671,6 @@ [[package]] | ||
| name = "writeable" | ||
| version = "0.5.0" | ||
| version = "0.5.1" | ||
| dependencies = [ | ||
| "criterion", | ||
| "icu_benchmark_macros", | ||
| "rand", | ||
| ] |
+7
-5
@@ -15,3 +15,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "writeable" | ||
| version = "0.5.0" | ||
| version = "0.5.1" | ||
| authors = ["The ICU4X Project Developers"] | ||
@@ -33,5 +33,11 @@ include = [ | ||
| [package.metadata.workspaces] | ||
| independent = true | ||
| [package.metadata.docs.rs] | ||
| all-features = true | ||
| [package.metadata.cargo-all-features] | ||
| denylist = ["bench"] | ||
| [lib] | ||
@@ -48,5 +54,2 @@ path = "src/lib.rs" | ||
| [dev-dependencies.icu_benchmark_macros] | ||
| version = "0.7" | ||
| [dev-dependencies.rand] | ||
@@ -58,2 +61,1 @@ version = "0.8" | ||
| bench = [] | ||
| default = [] |
+53
-47
@@ -10,8 +10,8 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| macro_rules! impl_write_num { | ||
| ($u:ty, $i:ty, $test:ident, $log10:ident) => { | ||
| ($u:ty, $i:ty, $test:ident, $max_ilog_10:expr) => { | ||
| impl $crate::Writeable for $u { | ||
| fn write_to<W: core::fmt::Write + ?Sized>(&self, sink: &mut W) -> core::fmt::Result { | ||
| let mut buf = [b'0'; $log10(<$u>::MAX) as usize + 1]; | ||
| let mut buf = [b'0'; $max_ilog_10 + 1]; | ||
| let mut n = *self; | ||
| let mut i = buf.len(); | ||
| let mut i = $max_ilog_10 + 1; | ||
| #[allow(clippy::indexing_slicing)] // n < 10^i | ||
@@ -33,36 +33,34 @@ while n != 0 { | ||
| fn writeable_length_hint(&self) -> $crate::LengthHint { | ||
| $crate::LengthHint::exact(if *self == 0 { | ||
| 1 | ||
| } else { | ||
| $log10(*self) as usize + 1 | ||
| }) | ||
| LengthHint::exact(self.checked_ilog10().unwrap_or(0) as usize + 1) | ||
| } | ||
| } | ||
| // TODO: use the library functions once stabilized. | ||
| // https://github.com/unicode-org/icu4x/issues/1428 | ||
| #[inline] | ||
| const fn $log10(s: $u) -> u32 { | ||
| let b = (<$u>::BITS - 1) - s.leading_zeros(); | ||
| // s ∈ [2ᵇ, 2ᵇ⁺¹-1] => ⌊log₁₀(s)⌋ ∈ [⌊log₁₀(2ᵇ)⌋, ⌊log₁₀(2ᵇ⁺¹-1)⌋] | ||
| // <=> ⌊log₁₀(s)⌋ ∈ [⌊log₁₀(2ᵇ)⌋, ⌊log₁₀(2ᵇ⁺¹)⌋] | ||
| // <=> ⌊log₁₀(s)⌋ ∈ [⌊b log₁₀(2)⌋, ⌊(b+1) log₁₀(2)⌋] | ||
| // The second line holds because there is no integer in | ||
| // [log₁₀(2ᶜ-1), log₁₀(2ᶜ)], if there were, there'd be some 10ⁿ in | ||
| // [2ᶜ-1, 2ᶜ], but it can't be 2ᶜ-1 due to parity nor 2ᶜ due to prime | ||
| // factors. | ||
| impl ILog10Ext for $u { | ||
| fn checked_ilog10(self) -> Option<u32> { | ||
| if self == 0 { | ||
| return None; | ||
| } | ||
| let b = (<$u>::BITS - 1) - self.leading_zeros(); | ||
| // self ∈ [2ᵇ, 2ᵇ⁺¹-1] => ⌊log₁₀(self)⌋ ∈ [⌊log₁₀(2ᵇ)⌋, ⌊log₁₀(2ᵇ⁺¹-1)⌋] | ||
| // <=> ⌊log₁₀(self)⌋ ∈ [⌊log₁₀(2ᵇ)⌋, ⌊log₁₀(2ᵇ⁺¹)⌋] | ||
| // <=> ⌊log₁₀(self)⌋ ∈ [⌊b log₁₀(2)⌋, ⌊(b+1) log₁₀(2)⌋] | ||
| // The second line holds because there is no integer in | ||
| // [log₁₀(2ᶜ-1), log₁₀(2ᶜ)], if there were, there'd be some 10ⁿ in | ||
| // [2ᶜ-1, 2ᶜ], but it can't be 2ᶜ-1 due to parity nor 2ᶜ due to prime | ||
| // factors. | ||
| const M: u32 = (core::f64::consts::LOG10_2 * (1 << 26) as f64) as u32; | ||
| let low = (b * M) >> 26; | ||
| let high = ((b + 1) * M) >> 26; | ||
| const M: u32 = (core::f64::consts::LOG10_2 * (1 << 26) as f64) as u32; | ||
| let low = (b * M) >> 26; | ||
| let high = ((b + 1) * M) >> 26; | ||
| // If the bounds aren't tight (e.g. 87 ∈ [64, 127] ⟹ ⌊log₁₀(87)⌋ ∈ [1,2]), | ||
| // compare to 10ʰ (100). This shouldn't happen too often as there are more | ||
| // powers of 2 than 10 (it happens for 14% of u32s). | ||
| if high == low { | ||
| low | ||
| } else if s < (10 as $u).pow(high) { | ||
| low | ||
| } else { | ||
| high | ||
| // If the bounds aren't tight (e.g. 87 ∈ [64, 127] ⟹ ⌊log₁₀(87)⌋ ∈ [1,2]), | ||
| // compare to 10ʰ (100). This shouldn't happen too often as there are more | ||
| // powers of 2 than 10 (it happens for 14% of u32s). | ||
| Some(if high == low { | ||
| low | ||
| } else if self < (10 as $u).pow(high) { | ||
| low | ||
| } else { | ||
| high | ||
| }) | ||
| } | ||
@@ -89,3 +87,3 @@ } | ||
| assert_writeable_eq!(&(0 as $u), "0"); | ||
| assert_writeable_eq!(&(0 as $u), "0"); | ||
| assert_writeable_eq!(&(0 as $i), "0"); | ||
| assert_writeable_eq!(&(-0 as $i), "0"); | ||
@@ -95,2 +93,5 @@ assert_writeable_eq!(&(1 as $u), "1"); | ||
| assert_writeable_eq!(&(-1 as $i), "-1"); | ||
| assert_writeable_eq!(&(9 as $u), "9"); | ||
| assert_writeable_eq!(&(9 as $i), "9"); | ||
| assert_writeable_eq!(&(-9 as $i), "-9"); | ||
| assert_writeable_eq!(&(10 as $u), "10"); | ||
@@ -119,15 +120,20 @@ assert_writeable_eq!(&(10 as $i), "10"); | ||
| impl_write_num!(u8, i8, test_u8, log10_u8); | ||
| impl_write_num!(u16, i16, test_u16, log10_u16); | ||
| impl_write_num!(u32, i32, test_u32, log10_u32); | ||
| impl_write_num!(u64, i64, test_u64, log10_u64); | ||
| impl_write_num!(u128, i128, test_u128, log10_u128); | ||
| #[test] | ||
| fn assert_log10_approximation() { | ||
| for i in 1..u128::BITS { | ||
| assert_eq!(i * 59 / 196, 2f64.powf(i.into()).log10().floor() as u32); | ||
| } | ||
| /// `checked_ilog10` is added as a method on integer types in 1.67. | ||
| /// This extension trait provides it for older compilers. | ||
| trait ILog10Ext: Sized { | ||
| fn checked_ilog10(self) -> Option<u32>; | ||
| } | ||
| impl_write_num!(u8, i8, test_u8, 2); | ||
| impl_write_num!(u16, i16, test_u16, 4); | ||
| impl_write_num!(u32, i32, test_u32, 9); | ||
| impl_write_num!(u64, i64, test_u64, 19); | ||
| impl_write_num!(u128, i128, test_u128, 38); | ||
| impl_write_num!( | ||
| usize, | ||
| isize, | ||
| test_usize, | ||
| if usize::MAX as u64 == u64::MAX { 19 } else { 9 } | ||
| ); | ||
| impl Writeable for str { | ||
@@ -202,3 +208,3 @@ #[inline] | ||
| fn test_string_impls() { | ||
| fn check_writeable_slice<W: Writeable>(writeables: &[W]) { | ||
| fn check_writeable_slice<W: Writeable + core::fmt::Display>(writeables: &[W]) { | ||
| assert_writeable_eq!(&writeables[0], ""); | ||
@@ -213,8 +219,8 @@ assert_writeable_eq!(&writeables[1], "abc"); | ||
| // test String impl | ||
| let arr: &[String] = &["".to_string(), "abc".to_string()]; | ||
| let arr: &[String] = &[String::new(), "abc".to_owned()]; | ||
| check_writeable_slice(arr); | ||
| // test &T impl | ||
| let arr: &[&String] = &[&"".to_string(), &"abc".to_string()]; | ||
| let arr: &[&String] = &[&String::new(), &"abc".to_owned()]; | ||
| check_writeable_slice(arr); | ||
| } |
+54
-6
@@ -139,2 +139,24 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| /// [`Part`]s are used as annotations for formatted strings. For example, a string like | ||
| /// `Alice, Bob` could assign a `NAME` part to the substrings `Alice` and `Bob`, and a | ||
| /// `PUNCTUATION` part to `, `. This allows for example to apply styling only to names. | ||
| /// | ||
| /// `Part` contains two fields, whose usage is left up to the producer of the [`Writeable`]. | ||
| /// Conventionally, the `category` field will identify the formatting logic that produces | ||
| /// the string/parts, whereas the `value` field will have semantic meaning. `NAME` and | ||
| /// `PUNCTUATION` could thus be defined as | ||
| /// ``` | ||
| /// # use writeable::Part; | ||
| /// const NAME: Part = Part { | ||
| /// category: "userlist", | ||
| /// value: "name", | ||
| /// }; | ||
| /// const PUNCTUATION: Part = Part { | ||
| /// category: "userlist", | ||
| /// value: "punctuation", | ||
| /// }; | ||
| /// ``` | ||
| /// | ||
| /// That said, consumers should not usually have to inspect `Part` internals. Instead, | ||
| /// formatters should expose the `Part`s they produces as constants. | ||
| #[derive(Clone, Copy, Debug, PartialEq)] | ||
@@ -244,3 +266,7 @@ #[allow(clippy::exhaustive_structs)] // stable | ||
| fn write_to_string(&self) -> Cow<str> { | ||
| let mut output = String::with_capacity(self.writeable_length_hint().capacity()); | ||
| let hint = self.writeable_length_hint(); | ||
| if hint.is_zero() { | ||
| return Cow::Borrowed(""); | ||
| } | ||
| let mut output = String::with_capacity(hint.capacity()); | ||
| let _ = self.write_to(&mut output); | ||
@@ -294,3 +320,6 @@ Cow::Owned(output) | ||
| /// impl Writeable for Demo { | ||
| /// fn write_to_parts<S: writeable::PartsWrite + ?Sized>(&self, sink: &mut S) -> fmt::Result { | ||
| /// fn write_to_parts<S: writeable::PartsWrite + ?Sized>( | ||
| /// &self, | ||
| /// sink: &mut S, | ||
| /// ) -> fmt::Result { | ||
| /// sink.with_part(WORD, |w| w.write_str("foo")) | ||
@@ -309,3 +338,9 @@ /// } | ||
| /// assert_writeable_parts_eq!(&Demo, "foo", [(0, 3, WORD)]); | ||
| /// assert_writeable_parts_eq!(&Demo, "foo", [(0, 3, WORD)], "Message: {}", "Hello World"); | ||
| /// assert_writeable_parts_eq!( | ||
| /// &Demo, | ||
| /// "foo", | ||
| /// [(0, 3, WORD)], | ||
| /// "Message: {}", | ||
| /// "Hello World" | ||
| /// ); | ||
| /// ``` | ||
@@ -323,6 +358,15 @@ #[macro_export] | ||
| let length_hint = $crate::Writeable::writeable_length_hint(actual_writeable); | ||
| assert!(length_hint.0 <= actual_str.len(), $($arg)*); | ||
| assert!( | ||
| length_hint.0 <= actual_str.len(), | ||
| "hint lower bound {} larger than actual length {}: {}", | ||
| length_hint.0, actual_str.len(), format!($($arg)*), | ||
| ); | ||
| if let Some(upper) = length_hint.1 { | ||
| assert!(actual_str.len() <= upper, $($arg)*); | ||
| assert!( | ||
| actual_str.len() <= upper, | ||
| "hint upper bound {} smaller than actual length {}: {}", | ||
| length_hint.0, actual_str.len(), format!($($arg)*), | ||
| ); | ||
| } | ||
| assert_eq!(actual_writeable.to_string(), $expected_str); | ||
| }}; | ||
@@ -348,2 +392,3 @@ } | ||
| } | ||
| assert_eq!(actual_writeable.to_string(), $expected_str); | ||
| }}; | ||
@@ -380,3 +425,6 @@ } | ||
| f(self)?; | ||
| self.parts.push((start, self.string.len(), part)); | ||
| let end = self.string.len(); | ||
| if start < end { | ||
| self.parts.push((start, end, part)); | ||
| } | ||
| Ok(()) | ||
@@ -383,0 +431,0 @@ } |
+4
-1
@@ -85,3 +85,6 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| /// impl Writeable for NonDeterministicWriteable { | ||
| /// fn write_to<W: fmt::Write + ?Sized>(&self, sink: &mut W) -> fmt::Result { | ||
| /// fn write_to<W: fmt::Write + ?Sized>( | ||
| /// &self, | ||
| /// sink: &mut W, | ||
| /// ) -> fmt::Result { | ||
| /// sink.write_str(if coin_flip() { &self.0 } else { &self.1 }) | ||
@@ -88,0 +91,0 @@ /// } |
Sorry, the diff of this file is not supported yet