+146
| // This file is part of ICU4X. For terms of use, please see the file | ||
| // called LICENSE at the top level of the ICU4X source tree | ||
| // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
| use crate::TryWriteable; | ||
| use crate::Writeable; | ||
| use core::fmt; | ||
| /// A [`Writeable`] that efficiently concatenates two other [`Writeable`]s. | ||
| /// | ||
| /// See the [`concat_writeable!`] macro for a convenient way to make one of these. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use writeable::adapters::Concat; | ||
| /// use writeable::assert_writeable_eq; | ||
| /// | ||
| /// assert_writeable_eq!(Concat("Number: ", 25), "Number: 25"); | ||
| /// ``` | ||
| /// | ||
| /// With [`TryWriteable`]: | ||
| /// | ||
| /// ``` | ||
| /// use writeable::adapters::Concat; | ||
| /// use writeable::assert_try_writeable_eq; | ||
| /// use writeable::TryWriteable; | ||
| /// | ||
| /// struct AlwaysPanic; | ||
| /// | ||
| /// impl TryWriteable for AlwaysPanic { | ||
| /// type Error = &'static str; | ||
| /// fn try_write_to_parts<W: writeable::PartsWrite + ?Sized>( | ||
| /// &self, | ||
| /// _sink: &mut W, | ||
| /// ) -> Result<Result<(), Self::Error>, core::fmt::Error> { | ||
| /// // Unreachable panic: the first Writeable errors, | ||
| /// // so the second Writeable is not evaluated. | ||
| /// panic!("this is a test to demonstrate unreachable code") | ||
| /// } | ||
| /// } | ||
| /// | ||
| /// let writeable0: Result<&str, &str> = Err("error message"); | ||
| /// let writeable1 = AlwaysPanic; | ||
| /// | ||
| /// assert_try_writeable_eq!( | ||
| /// Concat(writeable0, writeable1), | ||
| /// "error message", | ||
| /// Err("error message"), | ||
| /// ) | ||
| /// ``` | ||
| #[derive(Debug)] | ||
| #[allow(clippy::exhaustive_structs)] // designed for nesting | ||
| pub struct Concat<A, B>(pub A, pub B); | ||
| impl<A, B> Writeable for Concat<A, B> | ||
| where | ||
| A: Writeable, | ||
| B: Writeable, | ||
| { | ||
| #[inline] | ||
| fn write_to<W: fmt::Write + ?Sized>(&self, sink: &mut W) -> fmt::Result { | ||
| self.0.write_to(sink)?; | ||
| self.1.write_to(sink) | ||
| } | ||
| #[inline] | ||
| fn write_to_parts<S: crate::PartsWrite + ?Sized>(&self, sink: &mut S) -> fmt::Result { | ||
| self.0.write_to_parts(sink)?; | ||
| self.1.write_to_parts(sink) | ||
| } | ||
| #[inline] | ||
| fn writeable_length_hint(&self) -> crate::LengthHint { | ||
| self.0.writeable_length_hint() + self.1.writeable_length_hint() | ||
| } | ||
| } | ||
| impl<A, B, E> TryWriteable for Concat<A, B> | ||
| where | ||
| A: TryWriteable<Error = E>, | ||
| B: TryWriteable<Error = E>, | ||
| { | ||
| type Error = E; | ||
| #[inline] | ||
| fn try_write_to<W: fmt::Write + ?Sized>( | ||
| &self, | ||
| sink: &mut W, | ||
| ) -> Result<Result<(), Self::Error>, fmt::Error> { | ||
| if let Err(e) = self.0.try_write_to(sink)? { | ||
| return Ok(Err(e)); | ||
| } | ||
| self.1.try_write_to(sink) | ||
| } | ||
| #[inline] | ||
| fn try_write_to_parts<S: crate::PartsWrite + ?Sized>( | ||
| &self, | ||
| sink: &mut S, | ||
| ) -> Result<Result<(), Self::Error>, fmt::Error> { | ||
| if let Err(e) = self.0.try_write_to_parts(sink)? { | ||
| return Ok(Err(e)); | ||
| } | ||
| self.1.try_write_to_parts(sink) | ||
| } | ||
| #[inline] | ||
| fn writeable_length_hint(&self) -> crate::LengthHint { | ||
| self.0.writeable_length_hint() + self.1.writeable_length_hint() | ||
| } | ||
| } | ||
| impl<A, B> fmt::Display for Concat<A, B> | ||
| where | ||
| A: Writeable, | ||
| B: Writeable, | ||
| { | ||
| #[inline] | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| self.0.write_to(f)?; | ||
| self.1.write_to(f) | ||
| } | ||
| } | ||
| /// Returns a [`Writeable`] concatenating any number of [`Writeable`]s. | ||
| /// | ||
| /// The macro resolves to a nested [`Concat`]. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use writeable::assert_writeable_eq; | ||
| /// | ||
| /// let concatenated = writeable::concat_writeable!("Health: ", 5, '/', 8); | ||
| /// | ||
| /// assert_writeable_eq!(concatenated, "Health: 5/8"); | ||
| /// ``` | ||
| #[macro_export] | ||
| #[doc(hidden)] // macro | ||
| macro_rules! __concat_writeable { | ||
| // Base case: | ||
| ($x:expr) => ($x); | ||
| // `$x` followed by at least one `$y,` | ||
| ($x:expr, $($y:expr),+) => ( | ||
| // Call `concat_writeable!` recursively on the tail `$y` | ||
| $crate::adapters::Concat($x, $crate::concat_writeable!($($y),+)) | ||
| ) | ||
| } | ||
| #[doc(inline)] | ||
| pub use __concat_writeable as concat_writeable; |
| { | ||
| "git": { | ||
| "sha1": "29dfe2790b6cfdab94ca6a6b69f58ce54802dbf7" | ||
| "sha1": "e8d5b7561cf6cc4bee35286f5d5e569100dfa79d" | ||
| }, | ||
| "path_in_vcs": "utils/writeable" | ||
| } |
@@ -207,3 +207,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| b.iter(|| { | ||
| std::string::ToString::to_string(&DisplayMessage { | ||
| ToString::to_string(&DisplayMessage { | ||
| message: black_box(SHORT_STR), | ||
@@ -215,3 +215,3 @@ }) | ||
| b.iter(|| { | ||
| std::string::ToString::to_string(&DisplayMessage { | ||
| ToString::to_string(&DisplayMessage { | ||
| message: black_box(MEDIUM_STR), | ||
@@ -223,3 +223,3 @@ }) | ||
| b.iter(|| { | ||
| std::string::ToString::to_string(&DisplayMessage { | ||
| ToString::to_string(&DisplayMessage { | ||
| message: black_box(LONG_STR), | ||
@@ -286,3 +286,3 @@ }) | ||
| c.bench_function("complex/display_to_string/medium", |b| { | ||
| b.iter(|| std::string::ToString::to_string(&black_box(COMPLEX_WRITEABLE_MEDIUM))); | ||
| b.iter(|| ToString::to_string(&black_box(COMPLEX_WRITEABLE_MEDIUM))); | ||
| }); | ||
@@ -289,0 +289,0 @@ const REFERENCE_STRS: [&str; 6] = [ |
+57
-77
@@ -7,5 +7,5 @@ # This file is automatically @generated by Cargo. | ||
| name = "aho-corasick" | ||
| version = "1.1.3" | ||
| version = "1.1.4" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" | ||
| checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" | ||
| dependencies = [ | ||
@@ -23,5 +23,5 @@ "memchr", | ||
| name = "anstyle" | ||
| version = "1.0.13" | ||
| version = "1.0.14" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" | ||
| checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" | ||
@@ -36,5 +36,5 @@ [[package]] | ||
| name = "bumpalo" | ||
| version = "3.19.0" | ||
| version = "3.20.2" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" | ||
| checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" | ||
@@ -228,11 +228,11 @@ [[package]] | ||
| name = "itoa" | ||
| version = "1.0.15" | ||
| version = "1.0.18" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" | ||
| checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" | ||
| [[package]] | ||
| name = "js-sys" | ||
| version = "0.3.81" | ||
| version = "0.3.91" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" | ||
| checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" | ||
| dependencies = [ | ||
@@ -245,17 +245,11 @@ "once_cell", | ||
| name = "libc" | ||
| version = "0.2.177" | ||
| version = "0.2.183" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" | ||
| checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" | ||
| [[package]] | ||
| name = "log" | ||
| version = "0.4.28" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" | ||
| [[package]] | ||
| name = "memchr" | ||
| version = "2.7.6" | ||
| version = "2.8.0" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" | ||
| checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" | ||
@@ -273,5 +267,5 @@ [[package]] | ||
| name = "once_cell" | ||
| version = "1.21.3" | ||
| version = "1.21.4" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" | ||
| checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" | ||
@@ -323,5 +317,5 @@ [[package]] | ||
| name = "proc-macro2" | ||
| version = "1.0.103" | ||
| version = "1.0.106" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" | ||
| checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" | ||
| dependencies = [ | ||
@@ -333,5 +327,5 @@ "unicode-ident", | ||
| name = "quote" | ||
| version = "1.0.41" | ||
| version = "1.0.45" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" | ||
| checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" | ||
| dependencies = [ | ||
@@ -369,5 +363,5 @@ "proc-macro2", | ||
| name = "rand_core" | ||
| version = "0.9.3" | ||
| version = "0.9.5" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" | ||
| checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" | ||
| dependencies = [ | ||
@@ -399,5 +393,5 @@ "getrandom", | ||
| name = "regex" | ||
| version = "1.12.2" | ||
| version = "1.12.3" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" | ||
| checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" | ||
| dependencies = [ | ||
@@ -412,5 +406,5 @@ "aho-corasick", | ||
| name = "regex-automata" | ||
| version = "0.4.13" | ||
| version = "0.4.14" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" | ||
| checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" | ||
| dependencies = [ | ||
@@ -424,5 +418,5 @@ "aho-corasick", | ||
| name = "regex-syntax" | ||
| version = "0.8.8" | ||
| version = "0.8.10" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" | ||
| checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" | ||
@@ -436,8 +430,2 @@ [[package]] | ||
| [[package]] | ||
| name = "ryu" | ||
| version = "1.0.20" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" | ||
| [[package]] | ||
| name = "same-file" | ||
@@ -483,11 +471,11 @@ version = "1.0.6" | ||
| name = "serde_json" | ||
| version = "1.0.145" | ||
| version = "1.0.149" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" | ||
| checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" | ||
| dependencies = [ | ||
| "itoa", | ||
| "memchr", | ||
| "ryu", | ||
| "serde", | ||
| "serde_core", | ||
| "zmij", | ||
| ] | ||
@@ -497,5 +485,5 @@ | ||
| name = "syn" | ||
| version = "2.0.108" | ||
| version = "2.0.117" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" | ||
| checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" | ||
| dependencies = [ | ||
@@ -519,5 +507,5 @@ "proc-macro2", | ||
| name = "unicode-ident" | ||
| version = "1.0.20" | ||
| version = "1.0.24" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06" | ||
| checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" | ||
@@ -545,5 +533,5 @@ [[package]] | ||
| name = "wasm-bindgen" | ||
| version = "0.2.104" | ||
| version = "0.2.114" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" | ||
| checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" | ||
| dependencies = [ | ||
@@ -558,20 +546,6 @@ "cfg-if", | ||
| [[package]] | ||
| name = "wasm-bindgen-backend" | ||
| version = "0.2.104" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" | ||
| dependencies = [ | ||
| "bumpalo", | ||
| "log", | ||
| "proc-macro2", | ||
| "quote", | ||
| "syn", | ||
| "wasm-bindgen-shared", | ||
| ] | ||
| [[package]] | ||
| name = "wasm-bindgen-macro" | ||
| version = "0.2.104" | ||
| version = "0.2.114" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" | ||
| checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" | ||
| dependencies = [ | ||
@@ -584,10 +558,10 @@ "quote", | ||
| name = "wasm-bindgen-macro-support" | ||
| version = "0.2.104" | ||
| version = "0.2.114" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" | ||
| checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" | ||
| dependencies = [ | ||
| "bumpalo", | ||
| "proc-macro2", | ||
| "quote", | ||
| "syn", | ||
| "wasm-bindgen-backend", | ||
| "wasm-bindgen-shared", | ||
@@ -598,5 +572,5 @@ ] | ||
| name = "wasm-bindgen-shared" | ||
| version = "0.2.104" | ||
| version = "0.2.114" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" | ||
| checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" | ||
| dependencies = [ | ||
@@ -608,5 +582,5 @@ "unicode-ident", | ||
| name = "web-sys" | ||
| version = "0.3.81" | ||
| version = "0.3.91" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120" | ||
| checksum = "854ba17bb104abfb26ba36da9729addc7ce7f06f5c0f90f3c391f8461cca21f9" | ||
| dependencies = [ | ||
@@ -649,3 +623,3 @@ "js-sys", | ||
| name = "writeable" | ||
| version = "0.6.2" | ||
| version = "0.6.3" | ||
| dependencies = [ | ||
@@ -659,5 +633,5 @@ "criterion", | ||
| name = "zerocopy" | ||
| version = "0.8.27" | ||
| version = "0.8.47" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" | ||
| checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87" | ||
| dependencies = [ | ||
@@ -669,5 +643,5 @@ "zerocopy-derive", | ||
| name = "zerocopy-derive" | ||
| version = "0.8.27" | ||
| version = "0.8.47" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" | ||
| checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89" | ||
| dependencies = [ | ||
@@ -678,1 +652,7 @@ "proc-macro2", | ||
| ] | ||
| [[package]] | ||
| name = "zmij" | ||
| version = "1.0.21" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" |
+56
-1
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "writeable" | ||
| version = "0.6.2" | ||
| version = "0.6.3" | ||
| authors = ["The ICU4X Project Developers"] | ||
@@ -38,2 +38,8 @@ build = false | ||
| readme = "README.md" | ||
| keywords = [ | ||
| "formatting", | ||
| "write", | ||
| "string", | ||
| "no-std", | ||
| ] | ||
| license = "Unicode-3.0" | ||
@@ -82,1 +88,50 @@ repository = "https://github.com/unicode-org/icu4x" | ||
| version = "0.5.0" | ||
| [lints.clippy] | ||
| alloc-instead-of-core = "warn" | ||
| branches-sharing-code = "warn" | ||
| collection_is_never_read = "warn" | ||
| crosspointer_transmute = "warn" | ||
| dbg_macro = "warn" | ||
| debug_assert_with_mut_call = "warn" | ||
| doc_markdown = "warn" | ||
| exhaustive_enums = "deny" | ||
| exhaustive_structs = "deny" | ||
| fn_to_numeric_cast_any = "warn" | ||
| infinite_loop = "warn" | ||
| large_stack_arrays = "warn" | ||
| mismatching_type_param_order = "warn" | ||
| missing_fields_in_debug = "warn" | ||
| missing_transmute_annotations = "warn" | ||
| negative_feature_names = "warn" | ||
| or-fun-call = "warn" | ||
| same_functions_in_if_condition = "warn" | ||
| todo = "warn" | ||
| transmute_bytes_to_str = "warn" | ||
| transmute_int_to_bool = "warn" | ||
| transmute_int_to_non_zero = "warn" | ||
| transmute_ptr_to_ptr = "warn" | ||
| transmute_ptr_to_ref = "warn" | ||
| transmute_undefined_repr = "warn" | ||
| transmutes_expressible_as_ptr_casts = "warn" | ||
| trivially_copy_pass_by_ref = "deny" | ||
| unnecessary-wraps = "warn" | ||
| useless_transmute = "warn" | ||
| wildcard_dependencies = "warn" | ||
| [lints.rust] | ||
| missing_debug_implementations = "deny" | ||
| trivial_numeric_casts = "deny" | ||
| unused_lifetimes = "warn" | ||
| unused_macro_rules = "warn" | ||
| unused_qualifications = "warn" | ||
| [lints.rust.unexpected_cfgs] | ||
| level = "warn" | ||
| priority = 0 | ||
| check-cfg = [ | ||
| "cfg(icu4c_enable_renaming)", | ||
| "cfg(needs_alloc_error_handler)", | ||
| "cfg(icu4x_run_size_tests)", | ||
| "cfg(icu4x_unstable_fast_trie_only)", | ||
| ] |
@@ -50,4 +50,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| fn main() { | ||
| let (string, parts) = | ||
| writeable::_internal::writeable_to_parts_for_test(&WriteableMessage("world")); | ||
| let (string, parts) = _internal::writeable_to_parts_for_test(&WriteableMessage("world")); | ||
@@ -54,0 +53,0 @@ assert_eq!(string, "Hello world 😅"); |
+20
-0
@@ -100,2 +100,22 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| /// ``` | ||
| /// | ||
| /// This function can be combined with `writeable::concat_writeable!` to make an efficient | ||
| /// comparison between a string and a sequence of substrings: | ||
| /// | ||
| /// ``` | ||
| /// use core::cmp::Ordering; | ||
| /// | ||
| /// assert_eq!( | ||
| /// Ordering::Less, | ||
| /// writeable::cmp_str(&writeable::concat_writeable!("loop", 1), "loop12") | ||
| /// ); | ||
| /// assert_eq!( | ||
| /// Ordering::Equal, | ||
| /// writeable::cmp_str(&writeable::concat_writeable!("loop", 12), "loop12") | ||
| /// ); | ||
| /// assert_eq!( | ||
| /// Ordering::Greater, | ||
| /// writeable::cmp_str(&writeable::concat_writeable!("loop", 2), "loop12") | ||
| /// ); | ||
| /// ``` | ||
| #[inline] | ||
@@ -102,0 +122,0 @@ pub fn cmp_str(writeable: &impl Writeable, other: &str) -> Ordering { |
+6
-3
@@ -18,2 +18,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| #[expect(clippy::indexing_slicing)] // n < 10^i | ||
| #[allow(trivial_numeric_casts)] | ||
| while n != 0 { | ||
@@ -53,2 +54,3 @@ i -= 1; | ||
| #[test] | ||
| #[allow(trivial_numeric_casts)] | ||
| fn $test() { | ||
@@ -184,3 +186,4 @@ use $crate::assert_writeable_eq; | ||
| ($ty:path, T: $extra_bound:path) => { | ||
| impl<'a, T: ?Sized + Writeable + $extra_bound> Writeable for $ty { | ||
| #[allow(unused_qualifications)] | ||
| impl<T: ?Sized + Writeable + $extra_bound> Writeable for $ty { | ||
| #[inline] | ||
@@ -215,3 +218,3 @@ fn write_to<W: fmt::Write + ?Sized>(&self, sink: &mut W) -> fmt::Result { | ||
| #[cfg(feature = "alloc")] | ||
| impl_write_smart_pointer!(Cow<'a, T>, T: alloc::borrow::ToOwned); | ||
| impl_write_smart_pointer!(Cow<'_, T>, T: alloc::borrow::ToOwned); | ||
| #[cfg(feature = "alloc")] | ||
@@ -248,3 +251,3 @@ impl_write_smart_pointer!(alloc::boxed::Box<T>); | ||
| assert_eq!( | ||
| crate::cmp_str(&chars[j], &s), | ||
| cmp_str(&chars[j], &s), | ||
| chars[j].cmp(&chars[i]), | ||
@@ -251,0 +254,0 @@ "{:?} vs {:?}", |
+10
-5
@@ -14,8 +14,5 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| clippy::panic, | ||
| clippy::exhaustive_structs, | ||
| clippy::exhaustive_enums, | ||
| clippy::trivially_copy_pass_by_ref, | ||
| missing_debug_implementations, | ||
| ) | ||
| )] | ||
| #![warn(missing_docs)] | ||
@@ -84,2 +81,3 @@ //! This crate defines [`Writeable`], a trait representing an object that can be written to a | ||
| mod cmp; | ||
| mod concat; | ||
| #[cfg(feature = "either")] | ||
@@ -104,2 +102,3 @@ mod either; | ||
| pub use cmp::{cmp_str, cmp_utf8}; | ||
| pub use concat::concat_writeable; | ||
| #[cfg(feature = "alloc")] | ||
@@ -113,2 +112,3 @@ pub use to_string_or_borrow::to_string_or_borrow; | ||
| pub use concat::Concat; | ||
| pub use parts_write_adapter::CoreWriteAsPartsWrite; | ||
@@ -119,2 +119,4 @@ pub use parts_write_adapter::WithPart; | ||
| /// A lossy wrapper for a [`TryWriteable`] that implements [`Writeable`] | ||
| /// and ignores any errors. | ||
| #[derive(Debug)] | ||
@@ -168,2 +170,3 @@ #[allow(clippy::exhaustive_structs)] // newtype | ||
| impl LengthHint { | ||
| /// Unknown | ||
| pub fn undefined() -> Self { | ||
@@ -242,2 +245,3 @@ Self(0, None) | ||
| #[allow(clippy::exhaustive_structs)] // stable | ||
| #[allow(missing_docs)] // behavior not defined, explained in type docs | ||
| pub struct Part { | ||
@@ -260,2 +264,3 @@ pub category: &'static str, | ||
| pub trait PartsWrite: fmt::Write { | ||
| /// The recursive sink | ||
| type SubPartsWrite: PartsWrite + ?Sized; | ||
@@ -382,3 +387,3 @@ | ||
| (@display, $type:ty) => { | ||
| /// This trait is implemented for compatibility with [`fmt!`](alloc::fmt). | ||
| /// This trait is implemented for compatibility with [`fmt!`](core::fmt). | ||
| /// To create a string, [`Writeable::write_to_string`] is usually more efficient. | ||
@@ -385,0 +390,0 @@ impl core::fmt::Display for $type { |
@@ -84,3 +84,5 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| pub struct WithPart<T: ?Sized> { | ||
| /// The [`Part`] | ||
| pub part: Part, | ||
| /// The value | ||
| pub writeable: T, | ||
@@ -87,0 +89,0 @@ } |
+2
-0
@@ -49,2 +49,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| #[doc(hidden)] | ||
| pub fn writeable_to_parts_for_test<W: Writeable>( | ||
@@ -65,2 +66,3 @@ writeable: &W, | ||
| #[expect(clippy::type_complexity)] | ||
| #[doc(hidden)] | ||
| pub fn try_writeable_to_parts_for_test<W: TryWriteable>( | ||
@@ -67,0 +69,0 @@ writeable: &W, |
@@ -96,2 +96,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| pub trait TryWriteable { | ||
| /// The error type | ||
| type Error; | ||
@@ -98,0 +99,0 @@ |
Sorry, the diff of this file is not supported yet