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 databake::*; 7 8 impl Bake for LanguageIdentifier { bake(&self, env: &CrateEnv) -> TokenStream9 fn bake(&self, env: &CrateEnv) -> TokenStream { 10 env.insert("icu_locale_core"); 11 let repr = self.to_string(); 12 if self.variants.len() <= 1 { 13 quote! { 14 icu_locale_core::langid!(#repr) 15 } 16 } else { 17 quote! { 18 icu_locale_core::LanguageIdentifier::try_from_str(#repr).unwrap() 19 } 20 } 21 } 22 } 23