Debian Codegraph @

third_party/rust/icu_locid/src/databake.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 use crate::LanguageIdentifier;
6 use alloc::string::ToString;
7 use databake::*;
8
9 impl Bake for LanguageIdentifier {
10 fn bake(&self, env: &CrateEnv) -> TokenStream {
11 env.insert("icu_locid");
12 let repr = self.to_string();
13 if self.variants.len() <= 1 {
14 quote! {
15 icu_locid::langid!(#repr)
16 }
17 } else {
18 quote! {
19 icu_locid::LanguageIdentifier::from_str(#repr).unwrap()
20 }
21 }
22 }
23 }