-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds Databake, Yokeable, and ZeroFrom. Serde will follow.
- Loading branch information
Showing
8 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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 core::any::TypeId; | ||
|
||
use crate::SinglePlaceholder; | ||
|
||
use super::*; | ||
use ::databake::{quote, Bake, CrateEnv, TokenStream}; | ||
|
||
impl<B, Store> Bake for Pattern<B, Store> | ||
where | ||
B: 'static, | ||
Store: Bake, | ||
{ | ||
fn bake(&self, ctx: &CrateEnv) -> TokenStream { | ||
ctx.insert("icu_pattern"); | ||
let store = self.store.bake(ctx); | ||
let b = if TypeId::of::<B>() == TypeId::of::<SinglePlaceholder>() { | ||
quote!(icu_pattern::SinglePlaceholder) | ||
} else { | ||
unreachable!("all impls of sealed trait PatternBackend should be covered") | ||
}; | ||
quote! { | ||
icu_pattern::Pattern::<#b, _>::from_store_unchecked(#store) | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
/* | ||
Test currently ignored because test_bake is broken: | ||
left: "icu_pattern :: Pattern :: < icu_pattern :: SinglePlaceholder , _ > :: from_store_unchecked (alloc :: borrow :: Cow :: Borrowed (\"\"))" | ||
right: "icu_pattern :: Pattern ::< icu_pattern :: SinglePlaceholder , _ >:: from_store_unchecked (alloc :: borrow :: Cow :: Borrowed (\"\"))" | ||
*/ | ||
#[ignore] | ||
fn test_baked() { | ||
use ::databake::test_bake; | ||
use alloc::borrow::Cow; | ||
test_bake!( | ||
Pattern<SinglePlaceholder, Cow<str>>, | ||
const: crate::Pattern::<crate::SinglePlaceholder, _>::from_store_unchecked(alloc::borrow::Cow::Borrowed("")), | ||
icu_pattern | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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 ). | ||
|
||
#![allow(non_camel_case_types, non_snake_case)] | ||
|
||
extern crate alloc; | ||
|
||
use alloc::borrow::Cow; | ||
use icu_pattern::{Pattern, SinglePlaceholder}; | ||
|
||
#[cfg_attr(feature = "yoke", derive(yoke::Yokeable))] | ||
#[cfg_attr(feature = "zerofrom", derive(zerofrom::ZeroFrom))] | ||
// #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] | ||
#[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = crate))] | ||
struct DeriveTest_SinglePlaceholderPattern_ZeroVec<'data> { | ||
// #[cfg_attr(feature = "serde", serde(borrow))] | ||
_data: Pattern<SinglePlaceholder, Cow<'data, str>>, | ||
} | ||
|
||
#[test] | ||
/* | ||
Test currently ignored because test_bake is broken: | ||
left: "crate :: DeriveTest_SinglePlaceholderPattern_ZeroVec { _data : icu_pattern :: Pattern :: < icu_pattern :: SinglePlaceholder , _ > :: from_store_unchecked (alloc :: borrow :: Cow :: Borrowed (\"\")) , }" | ||
right: "crate :: DeriveTest_SinglePlaceholderPattern_ZeroVec { _data : icu_pattern :: Pattern ::< icu_pattern :: SinglePlaceholder , _ >:: from_store_unchecked (alloc :: borrow :: Cow :: Borrowed (\"\")) , }" | ||
*/ | ||
#[ignore] | ||
#[cfg(all(feature = "databake", feature = "alloc"))] | ||
fn bake_SinglePlaceholderPattern_ZeroVec() { | ||
use databake::*; | ||
extern crate std; | ||
test_bake!( | ||
DeriveTest_SinglePlaceholderPattern_ZeroVec<'static>, | ||
crate::DeriveTest_SinglePlaceholderPattern_ZeroVec { | ||
_data: icu_pattern::Pattern::<icu_pattern::SinglePlaceholder, _>::from_store_unchecked( | ||
alloc::borrow::Cow::Borrowed(""), | ||
) | ||
}, | ||
); | ||
} |