Skip to content

Commit

Permalink
Add arena feature
Browse files Browse the repository at this point in the history
  • Loading branch information
semtexzv committed Sep 7, 2023
1 parent 4dfd584 commit 67f72ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions protokit_binformat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ repository = "https://github.com/semtexzv/protokit"
authors = ["<semtexzv@gmail.com>"]
description = "Usable protocol buffers"

[features]
default = ["arena"]
arena = ["bumpalo", "bumpalo/boxed", "bumpalo/collections"]

[dependencies.derive]
package = "protokit_derive"
path = "../protokit_derive"
Expand All @@ -16,3 +20,4 @@ version = "0.0.2"
[dependencies]
indexmap = "1"
thiserror = "1"
bumpalo = { version = "3.13.0", optional = true, default_features = false }
17 changes: 17 additions & 0 deletions protokit_binformat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ where
}
}

#[cfg(feature = "arena")]
impl<'buf, 'arena, T> BinProto<'buf> for bumpalo::boxed::Box<'arena, T>
where T: BinProto<'buf>
{
fn merge_field(&mut self, tag_wire: u32, stream: &mut InputStream<'buf>) -> Result<()> {
self.deref_mut().merge_field(tag_wire, stream)
}

fn size(&self, stack: &mut SizeStack) -> usize {
self.deref().size(stack)
}

fn encode(&self, stream: &mut OutputStream) {
self.deref().encode(stream)
}
}

pub trait Varint: Default + Debug + Clone + Copy {
fn from_u64(v: u64) -> Self;
fn into_u64(self) -> u64;
Expand Down

0 comments on commit 67f72ac

Please sign in to comment.