Debian Codegraph @

third_party/rust/icu_provider_adapters/src/fork/macros.rs

raw
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5 /// Make a forking data provider with an arbitrary number of inner providers
6 /// that are known at build time.
7 ///
8 /// # Examples
9 ///
10 /// ```
11 /// use icu_provider_adapters::fork::ForkByKeyProvider;
12 ///
13 /// // Some empty example providers:
14 /// #[derive(PartialEq, Debug)]
15 /// struct Provider1;
16 /// #[derive(PartialEq, Debug)]
17 /// struct Provider2;
18 /// #[derive(PartialEq, Debug)]
19 /// struct Provider3;
20 ///
21 /// // Combine them into one:
22 /// let forking1 = icu_provider_adapters::make_forking_provider!(
23 /// ForkByKeyProvider::new,
24 /// [Provider1, Provider2, Provider3,]
25 /// );
26 ///
27 /// // This is equivalent to:
28 /// let forking2 = ForkByKeyProvider::new(
29 /// Provider1,
30 /// ForkByKeyProvider::new(Provider2, Provider3),
31 /// );
32 ///
33 /// assert_eq!(forking1, forking2);
34 /// ```
35 #[macro_export]
36 macro_rules! make_forking_provider {
37 // Base case:
38 ($combo_p:path, [ $a:expr, $b:expr, ]) => {
39 $combo_p($a, $b)
40 };
41 // General list:
42 ($combo_p:path, [ $a:expr, $b:expr, $($c:expr),+, ]) => {
43 $combo_p($a, $crate::make_forking_provider!($combo_p, [ $b, $($c),+, ]))
44 };
45 }
46
47 #[cfg(test)]
48 mod test {
49 struct Provider1;
50 struct Provider2;
51 struct Provider3;
52
53 #[test]
54 fn test_make_forking_provider() {
55 make_forking_provider!(
56 crate::fork::ForkByKeyProvider::new,
57 [Provider1, Provider2, Provider3,]
58 );
59 }
60 }