Skip to content

Commit

Permalink
Added support functions to get the underlying storage container of st…
Browse files Browse the repository at this point in the history
…ructures
  • Loading branch information
Yuri6037 committed Aug 24, 2024
1 parent 68d7086 commit cf2877d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bp3d-protoc"
version = "1.0.0-rc.2.0.0"
version = "1.0.0-rc.2.1.0"
edition = "2021"
authors = ["Yuri Edward <yuri6037@outlook.com>"]
description = "BP3D protocol compiler/generator."
Expand Down
16 changes: 16 additions & 0 deletions compiler/src/gen/rust/structure.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ impl<T> {name}<T> {{
pub fn new(data: T) -> Self {{
Self {{ data }}
}}

pub fn into_inner(self) -> T {{
self.data
}}
}}

impl {name}<[u8; {byte_size}]> {{
Expand All @@ -29,6 +33,18 @@ impl<'a, T: AsMut<[u8]>> {name}<T> {{
}}
}}

impl<T: AsRef<[u8]>> AsRef<[u8]> for {name}<T> {{
fn as_ref(&self) -> &[u8] {{
self.data.as_ref()
}}
}}

impl<T: AsMut<[u8]>> AsMut<[u8]> for {name}<T> {{
fn as_mut(&mut self) -> &mut [u8] {{
self.data.as_mut()
}}
}}

pub const SIZE_{name:to_screaming_case}: usize = {byte_size};
#fragment pop

Expand Down

0 comments on commit cf2877d

Please sign in to comment.