Skip to content

Commit

Permalink
Impl Bake for BTreeMap (#4274)
Browse files Browse the repository at this point in the history
Part of #4266
  • Loading branch information
adamchalmers authored Nov 14, 2023
1 parent 62ccc20 commit e7178ec
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions utils/databake/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,33 @@ fn btree_set() {
);
}

impl<K, V> Bake for alloc::collections::BTreeMap<K, V>
where
K: Bake,
V: Bake,
{
fn bake(&self, ctx: &CrateEnv) -> TokenStream {
ctx.insert("alloc");
let data = self.iter().map(|(k, v)| {
let k = k.bake(ctx);
let v = v.bake(ctx);
quote!((#k, #v))
});
quote! {
alloc::collections::BTreeMap::from([#(#data),*])
}
}
}

#[test]
fn btree_map() {
test_bake!(
alloc::collections::BTreeMap<u8, u8>,
alloc::collections::BTreeMap::from([(1u8, 2u8), (2u8, 4u8)]),
alloc
);
}

impl Bake for String {
fn bake(&self, _: &CrateEnv) -> TokenStream {
quote! {
Expand Down

0 comments on commit e7178ec

Please sign in to comment.