Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/pattern/tests/derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct DeriveTest_SinglePlaceholderPattern_Cow<'data> {
borrow,
deserialize_with = "icu_pattern::deserialize_borrowed_cow::<SinglePlaceholder, _>"
)]
data: Cow<'data, Pattern<SinglePlaceholder>>,
pub data: Cow<'data, Pattern<SinglePlaceholder>>,
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tutorials/data-provider-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ icu_provider::data_marker!(CustomV1, Custom<'static>);
#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize, databake::Bake, yoke::Yokeable, zerofrom::ZeroFrom)]
#[databake(path = crate)]
pub struct Custom<'data> {
message: Cow<'data, str>,
pub message: Cow<'data, str>,
};

icu_provider::data_struct!(Custom<'_>);
Expand Down
8 changes: 4 additions & 4 deletions utils/databake/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions utils/databake/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use syn::{
parse::{Parse, ParseStream},
parse_macro_input,
punctuated::Punctuated,
DeriveInput, Ident, Path, PathSegment, Token,
Data, DeriveInput, Ident, Path, PathSegment, Token, Visibility,
};
use synstructure::{AddBounds, Structure};

Expand Down Expand Up @@ -68,7 +68,12 @@ fn bake_derive_impl(input: &DeriveInput) -> TokenStream2 {
quote! { let #ident = #ident.bake(env); }
});

let constructor = vi.construct(|_, i| {
let constructor = vi.construct(|f, i| {
assert!(
f.vis == syn::parse_str::<Visibility>("pub").unwrap()
|| matches!(input.data, Data::Enum(_)),
"deriving Bake requires public fields"
);
let ident = &vi.bindings()[i].binding;
quote! { # #ident }
});
Expand Down
14 changes: 7 additions & 7 deletions utils/databake/derive/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use databake::*;
#[derive(Bake)]
#[databake(path = test)]
pub struct IntExample {
x: u8,
pub x: u8,
}

#[test]
Expand All @@ -20,8 +20,8 @@ fn test_int_example() {
#[derive(Bake)]
#[databake(path = test)]
pub struct GenericsExample<T> {
x: u32,
y: T,
pub x: u32,
pub y: T,
}

#[test]
Expand All @@ -40,10 +40,10 @@ fn test_generics_example() {
#[derive(Bake)]
#[databake(path = test)]
pub struct CowExample<'a> {
x: u8,
y: &'a str,
z: alloc::borrow::Cow<'a, str>,
w: alloc::borrow::Cow<'a, [u8]>,
pub x: u8,
pub y: &'a str,
pub z: alloc::borrow::Cow<'a, str>,
pub w: alloc::borrow::Cow<'a, [u8]>,
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions utils/databake/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use quote::quote;
/// #[derive(Bake)]
/// #[databake(path = my_crate)]
/// struct Data {
/// number: usize,
/// string: AsStaticStr<String>, // can be written as StringAsStaticStr
/// pub number: usize,
/// pub string: AsStaticStr<String>, // can be written as StringAsStaticStr
/// }
///
/// let data = Data {
Expand Down Expand Up @@ -139,7 +139,7 @@ pub type StringAsStaticStr = AsStaticStr<String>;
/// #[derive(Bake, Default)]
/// #[databake(path = my_crate)]
/// struct Data {
/// numbers: IteratorAsRefSlice<Vec<usize>, usize>, // can be written as `VecAsRefSlice<usize>`
/// pub numbers: IteratorAsRefSlice<Vec<usize>, usize>, // can be written as `VecAsRefSlice<usize>`
/// }
///
/// let mut data = Data::default();
Expand Down
16 changes: 8 additions & 8 deletions utils/databake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
//! #[derive(Bake)]
//! #[databake(path = my_crate)]
//! struct MyStruct {
//! number: u32,
//! string: &'static str,
//! slice: &'static [bool],
//! pub number: u32,
//! pub string: &'static str,
//! pub slice: &'static [bool],
//! }
//!
//! #[derive(Bake)]
//! #[databake(path = my_crate)]
//! struct AnotherOne(MyStruct, char);
//! struct AnotherOne(pub MyStruct, pub char);
//! ```
//!
//! # Testing
Expand All @@ -48,13 +48,13 @@
//! # #[derive(Bake)]
//! # #[databake(path = my_crate)]
//! # struct MyStruct {
//! # number: u32,
//! # string: &'static str,
//! # slice: &'static [bool],
//! # pub number: u32,
//! # pub string: &'static str,
//! # pub slice: &'static [bool],
//! # }
//! # #[derive(Bake)]
//! # #[databake(path = my_crate)]
//! # struct AnotherOne(MyStruct, char);
//! # struct AnotherOne(pub MyStruct, pub char);
//! # fn main() {
//! test_bake!(
//! AnotherOne,
Expand Down
10 changes: 5 additions & 5 deletions utils/zerotrie/tests/derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zerovec::ZeroVec;
#[cfg_attr(feature = "databake", databake(path = crate))]
struct DeriveTest_ZeroTrie_ZeroVec<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroTrie<ZeroVec<'data, u8>>,
pub _data: ZeroTrie<ZeroVec<'data, u8>>,
}

#[test]
Expand All @@ -44,7 +44,7 @@ fn bake_ZeroTrie_ZeroVec() {
#[cfg_attr(feature = "databake", databake(path = crate))]
struct DeriveTest_ZeroTrieSimpleAscii_ZeroVec<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroTrieSimpleAscii<ZeroVec<'data, u8>>,
pub _data: ZeroTrieSimpleAscii<ZeroVec<'data, u8>>,
}

#[test]
Expand All @@ -69,7 +69,7 @@ fn bake_ZeroTrieSimpleAscii_ZeroVec() {
#[cfg_attr(feature = "databake", databake(path = crate))]
struct DeriveTest_ZeroAsciiIgnoreCaseTrie_ZeroVec<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroAsciiIgnoreCaseTrie<ZeroVec<'data, u8>>,
pub _data: ZeroAsciiIgnoreCaseTrie<ZeroVec<'data, u8>>,
}

#[test]
Expand All @@ -94,7 +94,7 @@ fn bake_ZeroAsciiIgnoreCaseTrie_ZeroVec() {
#[cfg_attr(feature = "databake", databake(path = crate))]
struct DeriveTest_ZeroTriePerfectHash_ZeroVec<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroTriePerfectHash<ZeroVec<'data, u8>>,
pub _data: ZeroTriePerfectHash<ZeroVec<'data, u8>>,
}

#[test]
Expand All @@ -119,7 +119,7 @@ fn bake_ZeroTriePerfectHash_ZeroVec() {
#[cfg_attr(feature = "databake", databake(path = crate))]
struct DeriveTest_ZeroTrieExtendedCapacity_ZeroVec<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroTrieExtendedCapacity<ZeroVec<'data, u8>>,
pub _data: ZeroTrieExtendedCapacity<ZeroVec<'data, u8>>,
}

#[test]
Expand Down
18 changes: 9 additions & 9 deletions utils/zerovec/src/yoke_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ mod test {
#[cfg_attr(feature = "databake", databake(path = zerovec::yoke_impls::test))]
struct DeriveTest_ZeroVec<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroVec<'data, u16>,
pub _data: ZeroVec<'data, u16>,
}

#[test]
Expand All @@ -334,7 +334,7 @@ mod test {
#[cfg_attr(feature = "databake", databake(path = zerovec::yoke_impls::test))]
struct DeriveTest_ZeroSlice<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: &'data ZeroSlice<u16>,
pub _data: &'data ZeroSlice<u16>,
}

#[test]
Expand All @@ -354,7 +354,7 @@ mod test {
#[cfg_attr(feature = "databake", databake(path = zerovec::yoke_impls::test))]
struct DeriveTest_VarZeroVec<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: VarZeroVec<'data, str>,
pub _data: VarZeroVec<'data, str>,
}

#[test]
Expand All @@ -374,7 +374,7 @@ mod test {
#[cfg_attr(feature = "databake", databake(path = zerovec::yoke_impls::test))]
struct DeriveTest_VarZeroSlice<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: &'data VarZeroSlice<str>,
pub _data: &'data VarZeroSlice<str>,
}

#[test]
Expand All @@ -395,7 +395,7 @@ mod test {
#[yoke(prove_covariance_manually)]
struct DeriveTest_ZeroMap<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroMap<'data, [u8], str>,
pub _data: ZeroMap<'data, [u8], str>,
}

#[test]
Expand All @@ -422,7 +422,7 @@ mod test {
#[yoke(prove_covariance_manually)]
struct DeriveTest_ZeroMapBorrowed<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroMapBorrowed<'data, [u8], str>,
pub _data: ZeroMapBorrowed<'data, [u8], str>,
}

#[test]
Expand All @@ -449,7 +449,7 @@ mod test {
#[yoke(prove_covariance_manually)]
struct DeriveTest_ZeroMapWithULE<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroMap<'data, ZeroSlice<u32>, str>,
pub _data: ZeroMap<'data, ZeroSlice<u32>, str>,
}

#[test]
Expand All @@ -476,7 +476,7 @@ mod test {
#[yoke(prove_covariance_manually)]
struct DeriveTest_ZeroMap2d<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroMap2d<'data, u16, u16, str>,
pub _data: ZeroMap2d<'data, u16, u16, str>,
}

#[test]
Expand Down Expand Up @@ -505,7 +505,7 @@ mod test {
#[yoke(prove_covariance_manually)]
struct DeriveTest_ZeroMap2dBorrowed<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
_data: ZeroMap2dBorrowed<'data, u16, u16, str>,
pub _data: ZeroMap2dBorrowed<'data, u16, u16, str>,
}

#[test]
Expand Down