This commit is contained in:
Nicolas Stalder
2021-02-18 00:13:36 +01:00
parent eb500b9bf9
commit dc0284a589
6 changed files with 17 additions and 9 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ pub(crate) struct DeriveDecodableStruct {
}
impl DeriveDecodableStruct {
pub fn derive(s: Structure<'_>, data: &DataStruct, name: &Ident, attrs: &Vec<Attribute>) -> TokenStream {
pub fn derive(s: Structure<'_>, data: &DataStruct, name: &Ident, attrs: &[Attribute]) -> TokenStream {
let tag = extract_tag(name, attrs);
+1 -1
View File
@@ -12,7 +12,7 @@ pub(crate) struct DeriveEncodableStruct {
}
impl DeriveEncodableStruct {
pub fn derive(s: Structure<'_>, data: &DataStruct, name: &Ident, attrs: &Vec<Attribute>) -> TokenStream {
pub fn derive(s: Structure<'_>, data: &DataStruct, name: &Ident, attrs: &[Attribute]) -> TokenStream {
let tag = extract_tag(name, attrs);
+1 -1
View File
@@ -88,7 +88,7 @@ impl FieldAttrs {
}
}
fn extract_tag(name: &Ident, attrs: &Vec<Attribute>) -> u8 {
fn extract_tag(name: &Ident, attrs: &[Attribute]) -> u8 {
let mut tag = None;
for attr in attrs {
+1
View File
@@ -74,6 +74,7 @@ impl<'a> TaggedSlice<'a> {
}
/// Get the SIMPLE-TLV [`Header`] for this [`TaggedSlice`] value
#[allow(clippy::unnecessary_wraps)]
fn header(&self) -> Result<Header> {
Ok(Header {
tag: self.tag(),
+9 -2
View File
@@ -179,6 +179,13 @@ where
TaggedContainer: Tagged + Container
{
fn encoded_length(&self) -> Result<Length> {
#[allow(clippy::redundant_closure)]
// if we do as clippy tells, we get:
// 183 | let value_length = self.fields(Length::try_from)?;
// | ^^^^^^ one type is more general than the other
// |
// = note: expected type `FnOnce<(&[&dyn Encodable],)>`
// found type `FnOnce<(&[&dyn Encodable],)>`
let value_length = self.fields(|encodables| Length::try_from(encodables))?;
Header::new(Self::tag(), value_length)?.encoded_length() + value_length
}
@@ -268,8 +275,8 @@ impl_array!(
#[cfg(test)]
mod tests {
use core::convert::{TryFrom, TryInto};
use crate::{Decodable, Decoder, Encodable, Encoder, Error, Length, Result, Tag, TaggedSlice};
use core::convert::TryFrom;
use crate::{Decodable, Encodable, Error, Result, Tag, TaggedSlice};
use super::{Taggable, Tagged, Container};
// The types [u8; 2], [u8; 3], [u8; 4] stand in here for any types for the fields
+4 -4
View File
@@ -5,13 +5,13 @@
use simple_tlv::{Decodable, Encodable};
#[derive(Clone, Copy, Debug, Decodable, Encodable, Eq, PartialEq)]
#[tlv(tag = "0xAA")]
#[tlv(tag = "AA")]
struct S {
#[tlv(tag = "0x11")]
#[tlv(tag = "11")]
x: [u8; 2],
#[tlv(tag = "0x22")]
#[tlv(tag = "22")]
y: [u8; 3],
#[tlv(tag = "0x33")]
#[tlv(tag = "33")]
z: [u8; 4],
}