Skip to content

Commit

Permalink
Clean up code and lint with clippy.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-graj committed Jan 18, 2025
1 parent 6654cde commit 2e4ab2c
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 24 deletions.
2 changes: 2 additions & 0 deletions bin-proto-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ rust-version = "1.63.0"

description = "Derive macros for bin-proto"
license = "MIT"
readme = "../README.md"
repository = "https://github.com/wojciech-graj/bin-proto"
documentation = "https://docs.rs/bin-proto"
keywords = ["protocol", "binary", "bit", "codec", "serde"]
categories = ["encoding", "parsing"]

[lib]
proc-macro = true
Expand Down
12 changes: 6 additions & 6 deletions bin-proto-derive/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ pub enum AttrKind {
impl fmt::Display for AttrKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AttrKind::Enum => write!(f, "enum"),
AttrKind::Struct => write!(f, "struct"),
AttrKind::Variant => write!(f, "variant"),
AttrKind::Field => write!(f, "field"),
Self::Enum => write!(f, "enum"),
Self::Struct => write!(f, "struct"),
Self::Variant => write!(f, "variant"),
Self::Field => write!(f, "field"),
}
}
}
Expand All @@ -69,9 +69,9 @@ impl Attrs {
}
}

#[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
pub fn parse(attrs: &[syn::Attribute], kind: Option<AttrKind>, span: Span) -> Result<Self> {
let mut attribs = Attrs::default();
let mut attribs = Self::default();

let mut tag = None;
let mut tag_type = None;
Expand Down
4 changes: 2 additions & 2 deletions bin-proto-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
#![deny(clippy::pedantic, clippy::nursery, clippy::cargo)]
#![allow(clippy::module_name_repetitions, clippy::option_if_let_else)]

#[macro_use]
extern crate quote;
Expand Down
6 changes: 3 additions & 3 deletions bin-proto-derive/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ impl Enum {

let discriminant_value = match variant.discriminant.as_ref().map(|a| &a.1) {
Some(expr_lit) => expr_lit.clone(),
None => attrs
.discriminant
.ok_or(Error::new(variant.span(), "No discriminant for variant"))?,
None => attrs.discriminant.ok_or_else(|| {
Error::new(variant.span(), "No discriminant for variant")
})?,
};

let variant = EnumVariant {
Expand Down
1 change: 1 addition & 0 deletions bin-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ readme = "../README.md"
repository = "https://github.com/wojciech-graj/bin-proto"
documentation = "https://docs.rs/bin-proto"
keywords = ["protocol", "binary", "bit", "codec", "serde"]
categories = ["encoding", "parsing"]

[package.metadata.docs.rs]
all-features = true
Expand Down
10 changes: 5 additions & 5 deletions bin-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
//! ```
#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(clippy::pedantic)]
#![deny(clippy::pedantic, clippy::nursery, clippy::cargo)]
#![allow(
clippy::module_name_repetitions,
clippy::missing_errors_doc,
Expand Down Expand Up @@ -314,15 +314,15 @@ pub use bin_proto_derive::{ProtocolRead, ProtocolWrite};
mod bit_field;
mod bit_read;
mod bit_write;
#[macro_use]
mod tagged;
mod byte_order;
mod discriminable;
mod error;
mod flexible_array_member;
mod types;
#[macro_use]
mod protocol;
mod discriminable;
#[macro_use]
mod tagged;
mod types;
mod util;

pub extern crate bitstream_io;
Expand Down
2 changes: 0 additions & 2 deletions bin-proto/src/types/collections/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion bin-proto/src/types/cstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl<Ctx> ProtocolRead<Ctx> for CString {
loop {
let c: u8 = ProtocolRead::read(read, byte_order, ctx)?;
if c == 0x00 {
return Ok(CString::new(result)?);
return Ok(Self::new(result)?);
}
result.push(c);
}
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions bin-proto/src/types/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::marker::{PhantomData, PhantomPinned};

impl<Ctx, T> ProtocolRead<Ctx> for PhantomData<T> {
fn read(_: &mut dyn BitRead, _: ByteOrder, _: &mut Ctx) -> Result<Self> {
Ok(PhantomData)
Ok(Self)
}
}

Expand All @@ -15,7 +15,7 @@ impl<Ctx, T> ProtocolWrite<Ctx> for PhantomData<T> {

impl<Ctx> ProtocolRead<Ctx> for PhantomPinned {
fn read(_: &mut dyn BitRead, _: ByteOrder, _: &mut Ctx) -> Result<Self> {
Ok(PhantomPinned)
Ok(Self)
}
}

Expand Down
3 changes: 2 additions & 1 deletion bin-proto/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Utility types
mod array;
mod collections;
mod cstring;
mod list;
mod map;
mod marker;
mod net;
mod numerics;
Expand Down
4 changes: 2 additions & 2 deletions bin-proto/src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ where
ctx,
)?;

Ok(String::from_utf8(bytes)?)
Ok(Self::from_utf8(bytes)?)
}
}

Expand All @@ -34,7 +34,7 @@ impl<Ctx> UntaggedWrite<Ctx> for String {
impl<Ctx> FlexibleArrayMemberRead<Ctx> for String {
fn read(read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut Ctx) -> Result<Self> {
let bytes = util::read_items_to_eof(read, byte_order, ctx)?;
Ok(String::from_utf8(bytes)?)
Ok(Self::from_utf8(bytes)?)
}
}

Expand Down

0 comments on commit 2e4ab2c

Please sign in to comment.