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
38 changes: 25 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "embedded-command-macros"
version = "0.1.0"
version = "0.2.0"
edition = "2024"
description = "Macros for the embedded command crate family."
license = "CC-BY-NC-SA-4.0"
Expand Down
31 changes: 17 additions & 14 deletions macros/src/serac/vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn serialize_struct(s: DataStruct, info: &BodyInfo) -> TokenStream2 {
let types: Vec<_> = s.fields.iter().map(|field| &field.ty).collect();

let (ser_body, deser_body) = match &s.fields {
Fields::Unit => (quote! { Ok(()) }, quote! { Ok(Self) }),
Fields::Unit => (quote! { Ok(0) }, quote! { Ok(Self) }),
Fields::Unnamed(fields) => {
let attr_tags: Vec<_> = fields
.unnamed
Expand All @@ -64,12 +64,13 @@ fn serialize_struct(s: DataStruct, info: &BodyInfo) -> TokenStream2 {
(
quote! {
let mut dst = dst.into_iter();
let mut used = 0;

#(
#path::SerializeIter::serialize_iter(&self.#attr_tags, &mut dst)?;
used += #path::SerializeIter::serialize_iter(&self.#attr_tags, &mut dst)?;
)*

Ok(())
Ok(used)
},
quote! {
let mut src = src.into_iter();
Expand All @@ -94,12 +95,13 @@ fn serialize_struct(s: DataStruct, info: &BodyInfo) -> TokenStream2 {
(
quote! {
let mut dst = dst.into_iter();
let mut used = 0;

#(
#path::SerializeIter::serialize_iter(&self.#attr_idents, &mut dst)?;
used += #path::SerializeIter::serialize_iter(&self.#attr_idents, &mut dst)?;
)*

Ok(())
Ok(used)
},
quote! {
let mut src = src.into_iter();
Expand All @@ -118,7 +120,7 @@ fn serialize_struct(s: DataStruct, info: &BodyInfo) -> TokenStream2 {

quote! {
impl #impl_generics #path::SerializeIter for #implementer #ty_generics #where_clause {
fn serialize_iter<'a>(&self, dst: impl IntoIterator<Item = &'a mut <#path::encoding::vanilla::Vanilla as #path::encoding::Encoding>::Word>) -> Result<(), #path::error::EndOfInput>
fn serialize_iter<'a>(&self, dst: impl IntoIterator<Item = &'a mut <#path::encoding::vanilla::Vanilla as #path::encoding::Encoding>::Word>) -> Result<usize, #path::error::EndOfInput>
where
<#path::encoding::vanilla::Vanilla as #path::encoding::Encoding>::Word: 'a,
{
Expand Down Expand Up @@ -189,12 +191,12 @@ fn serialize_enum(e: DataEnum, info: &BodyInfo, repr: Type) -> TokenStream2 {

quote! {
#ident(#(#idents),*) => {
#path::SerializeIter::serialize_iter(&#tag_const, &mut dst)?;
used += #path::SerializeIter::serialize_iter(&#tag_const, &mut dst)?;
#(
#path::SerializeIter::serialize_iter(#idents, &mut dst)?;
used += #path::SerializeIter::serialize_iter(#idents, &mut dst)?;
)*

Ok(())
Ok(used)
}
}
}
Expand All @@ -207,12 +209,12 @@ fn serialize_enum(e: DataEnum, info: &BodyInfo, repr: Type) -> TokenStream2 {

quote! {
#ident{#(#idents),*} => {
#path::SerializeIter::serialize_iter(&#tag_const, &mut dst)?;
used += #path::SerializeIter::serialize_iter(&#tag_const, &mut dst)?;
#(
#path::SerializeIter::serialize_iter(#idents, &mut dst)?;
used += #path::SerializeIter::serialize_iter(#idents, &mut dst)?;
)*

Ok(())
Ok(used)
}
}
}
Expand Down Expand Up @@ -260,11 +262,12 @@ fn serialize_enum(e: DataEnum, info: &BodyInfo, repr: Type) -> TokenStream2 {

quote! {
impl #impl_generics #path::SerializeIter for #implementer #ty_generics #where_clause {
fn serialize_iter<'a>(&self, dst: impl IntoIterator<Item = &'a mut <#path::encoding::vanilla::Vanilla as #path::encoding::Encoding>::Word>) -> Result<(), #path::error::EndOfInput>
fn serialize_iter<'a>(&self, dst: impl IntoIterator<Item = &'a mut <#path::encoding::vanilla::Vanilla as #path::encoding::Encoding>::Word>) -> Result<usize, #path::error::EndOfInput>
where
<#path::encoding::vanilla::Vanilla as #path::encoding::Encoding>::Word: 'a,
{
let mut dst = dst.into_iter();
let mut used = 0;

#(
const #tag_consts: #repr = #tags;
Expand Down Expand Up @@ -379,7 +382,7 @@ pub fn impl_serialize_buf(item: TokenStream) -> TokenStream {
pub fn serialize_buf<'a>(
&self,
buf: &'a mut <#path::encoding::Vanilla as #path::Encoding>::Serialized<{ <Self as #path::SerializeBuf>::SIZE }>,
) where
) -> usize where
&'a mut <#path::encoding::Vanilla as #path::Encoding>::Serialized<{ <Self as #path::SerializeBuf>::SIZE }>:
IntoIterator<Item = &'a mut <#path::encoding::Vanilla as #path::Encoding>::Word> + 'a,
{
Expand Down
4 changes: 2 additions & 2 deletions serac/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "serac"
version = "0.1.0"
version = "0.2.0"
edition = "2024"
description = "A static, modular, and light-weight serialization framework."
license = "CC-BY-NC-SA-4.0"
repository = "https://github.com/adinack/embedded-command"

[dependencies]
macros = { package = "embedded-command-macros", version = "0.1.0" }
macros = { package = "embedded-command-macros", version = "0.2.0" }
fill-array = "0.2.1"

# for binary
Expand Down
Loading
Loading