Skip to content

Commit

Permalink
Fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Dec 19, 2024
1 parent 76f25ca commit 163c420
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 63 deletions.
6 changes: 3 additions & 3 deletions src/consts/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
/// * One enum called `MyFamilyEnum`.
/// * Another called `MyOtherFamilyEnum`.
/// * A marker trait called `MyMarkerTrait`. This can be used to
/// constain type parameter so that only `MyFamilyEnum` and
/// `MyOtherFamilyEnum` variants can be passed in as a value.
/// constain type parameter so that only `MyFamilyEnum` and
/// `MyOtherFamilyEnum` variants can be passed in as a value.
/// * A wrapper enum called `MyFamilyWrapperType`. The definition is
/// as follows:
/// as follows:
/// ```
/// enum MyFamilyEnum {
/// One,
Expand Down
42 changes: 21 additions & 21 deletions src/consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@
//! # Design decisions
//!
//! * Macros are exported so that these conventions are extensible and
//! usable for data types implemented by the user in the case of new
//! netlink families (which is supported by the protocol). In this
//! case, there is no way in which I can support every custom netlink
//! family but my aim is to make this library as flexible as possible
//! so that it is painless to hook your custom netlink data type into
//! the existing library support.
//! usable for data types implemented by the user in the case of new
//! netlink families (which is supported by the protocol). In this
//! case, there is no way in which I can support every custom netlink
//! family but my aim is to make this library as flexible as possible
//! so that it is painless to hook your custom netlink data type into
//! the existing library support.
//! * Enums are used so that:
//! * Values can be checked based on a finite number of inputs as
//! opposed to the range of whatever integer data type C defines as
//! the struct member type. This makes it easier to catch garbage
//! responses and corruption when an invalid netlink message is sent
//! to the kernel.
//! opposed to the range of whatever integer data type C defines as
//! the struct member type. This makes it easier to catch garbage
//! responses and corruption when an invalid netlink message is sent
//! to the kernel.
//! * Only the enum or an enum implementing a marker trait in the
//! case of type parameters can be used in the appropriate places
//! when constructing netlink messages. This takes guess work out of
//! which constants can be used where. Netlink documentation is not
//! always complete and sometimes takes a bit of trial and error
//! sending messages to the kernel to figure out if you are using
//! the correct constants. This setup should let you know at compile
//! time if you are doing something you should not be doing.
//! case of type parameters can be used in the appropriate places
//! when constructing netlink messages. This takes guess work out of
//! which constants can be used where. Netlink documentation is not
//! always complete and sometimes takes a bit of trial and error
//! sending messages to the kernel to figure out if you are using
//! the correct constants. This setup should let you know at compile
//! time if you are doing something you should not be doing.
//! * `UnrecognizedVariant` is included in each enum because
//! completeness cannot be guaranteed for every constant for every
//! protocol. This allows you to inspect the integer value returned
//! and if you are sure that it is correct, you can use it. If it is
//! a garbage value, this can also be useful for error reporting.
//! completeness cannot be guaranteed for every constant for every
//! protocol. This allows you to inspect the integer value returned
//! and if you are sure that it is correct, you can use it. If it is
//! a garbage value, this can also be useful for error reporting.
#[macro_use]
mod macros;
Expand Down
6 changes: 3 additions & 3 deletions src/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//!
//! There are four main types:
//! * [`Nlmsgerr`][crate::err::Nlmsgerr] - an application error
//! returned from netlink as a packet.
//! returned from netlink as a packet.
//! * [`NlError`][crate::err::NlError] - a general netlink error
//! wrapping application errors, serialization and deserialization
//! errors, and other errors that occur in `neli`.
//! wrapping application errors, serialization and deserialization
//! errors, and other errors that occur in `neli`.
//! * [`DeError`] - error while deserializing
//! * [`SerError`] - error while serializing
//!
Expand Down
2 changes: 1 addition & 1 deletion src/genl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ where
type GenlAttrHandle<'a, T> = AttrHandle<'a, GenlBuffer<T, Buffer>, Nlattr<T, Buffer>>;
type GenlAttrHandleMut<'a, T> = AttrHandleMut<'a, GenlBuffer<T, Buffer>, Nlattr<T, Buffer>>;

impl<'a, T> AttrHandle<'a, GenlBuffer<T, Buffer>, Nlattr<T, Buffer>>
impl<T> AttrHandle<'_, GenlBuffer<T, Buffer>, Nlattr<T, Buffer>>
where
T: NlAttrType,
{
Expand Down
22 changes: 11 additions & 11 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ pub enum IterationBehavior {
///
/// This iterator has two high-level options:
/// * Iterate indefinitely over messages. This is most
/// useful in the case of subscribing to messages in a
/// multicast group.
/// useful in the case of subscribing to messages in a
/// multicast group.
/// * Iterate until a message is returned with
/// [`Nlmsg::Done`][crate::consts::nl::Nlmsg::Done] is set.
/// This is most useful in the case of request-response workflows
/// where the iterator will parse and iterate through all of the
/// messages with [`NlmF::Multi`][crate::consts::nl::NlmF::Multi] set
/// until a message with
/// [`Nlmsg::Done`][crate::consts::nl::Nlmsg::Done] is
/// received at which point [`None`] will be returned indicating the
/// end of the response.
/// [`Nlmsg::Done`][crate::consts::nl::Nlmsg::Done] is set.
/// This is most useful in the case of request-response workflows
/// where the iterator will parse and iterate through all of the
/// messages with [`NlmF::Multi`][crate::consts::nl::NlmF::Multi] set
/// until a message with
/// [`Nlmsg::Done`][crate::consts::nl::Nlmsg::Done] is
/// received at which point [`None`] will be returned indicating the
/// end of the response.
pub struct NlMessageIter<'a, T, P> {
sock_ref: &'a mut NlSocketHandle,
next_is_none: Option<bool>,
Expand Down Expand Up @@ -111,7 +111,7 @@ where
}
}

impl<'a, T, P> Iterator for NlMessageIter<'a, T, P>
impl<T, P> Iterator for NlMessageIter<'_, T, P>
where
T: NlType + Debug,
P: for<'b> FromBytesWithInput<'b, Input = usize> + Debug,
Expand Down
30 changes: 15 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
//!
//! ## The project is broken down into the following modules:
//! * `attr` - This defines a generic interface for netlink attributes
//! (both generic and routing netlink attributes).
//! (both generic and routing netlink attributes).
//! * `consts` - This is where all of the C-defined constants are
//! wrapped into type safe enums for use in the library.
//! wrapped into type safe enums for use in the library.
//! * `err` - This module contains all of the protocol and
//! library-level errors encountered in the code.
//! library-level errors encountered in the code.
//! * `genl` - This code provides parsing for the generic netlink
//! * `iter` - This code handles iterating over received netlink
//! packets.
//! packets.
//! * `nl` - This is the top level netlink header code that handles
//! the header that all netlink messages are encapsulated in.
//! the header that all netlink messages are encapsulated in.
//! * `rtnl` - This module is for the routing netlink subsystem of the
//! netlink protocol.
//! netlink protocol.
//! * `socket` - This provides a socket structure for use in sending
//! and receiving messages and a number of convenience functions for
//! commonly encountered use cases.
//! and receiving messages and a number of convenience functions for
//! commonly encountered use cases.
//! * `types` - Data types used in serialization and deserialization of
//! packets.
//! packets.
//! * `utils` - Data types that primarily serve the purpose of handling
//! kernel data format conversions to easily usable Rust constructs
//! for the user.
//! kernel data format conversions to easily usable Rust constructs
//! for the user.
//!
//! ## Design decisions
//!
Expand Down Expand Up @@ -363,13 +363,13 @@ impl<'lt, T> FromBytes<'lt> for PhantomData<T> {
}
}

impl<'a> Size for &'a str {
impl Size for &'_ str {
fn unpadded_size(&self) -> usize {
self.len() + 1
}
}

impl<'a> ToBytes for &'a str {
impl ToBytes for &'_ str {
fn to_bytes(&self, buffer: &mut Cursor<Vec<u8>>) -> Result<(), SerError> {
buffer.write_all(self.as_bytes())?;
buffer.write_all(&[0])?;
Expand Down Expand Up @@ -415,13 +415,13 @@ impl<'a> FromBytesWithInput<'a> for String {
}
}

impl<'a> Size for &'a [u8] {
impl Size for &'_ [u8] {
fn unpadded_size(&self) -> usize {
self.len()
}
}

impl<'a> ToBytes for &'a [u8] {
impl ToBytes for &'_ [u8] {
fn to_bytes(&self, buffer: &mut Cursor<Vec<u8>>) -> Result<(), SerError> {
buffer.write_all(self)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/rtnl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ where
type RtAttrHandle<'a, T> = AttrHandle<'a, RtBuffer<T, Buffer>, Rtattr<T, Buffer>>;
type RtAttrHandleMut<'a, T> = AttrHandleMut<'a, RtBuffer<T, Buffer>, Rtattr<T, Buffer>>;

impl<'a, T> AttrHandle<'a, RtBuffer<T, Buffer>, Rtattr<T, Buffer>>
impl<T> AttrHandle<'_, RtBuffer<T, Buffer>, Rtattr<T, Buffer>>
where
T: RtaType,
{
Expand Down
16 changes: 8 additions & 8 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
//!
//! ## Important methods
//! * [`NlSocket::send`] and [`NlSocket::recv`] methods are meant to
//! be the most low level calls. They essentially do what the C
//! system calls `send` and `recv` do with very little abstraction.
//! be the most low level calls. They essentially do what the C
//! system calls `send` and `recv` do with very little abstraction.
//! * [`NlSocketHandle::send`] and [`NlSocketHandle::recv`] methods
//! are meant to provide an interface that is more idiomatic for
//! the library.
//! are meant to provide an interface that is more idiomatic for
//! the library.
//! * [`NlSocketHandle::iter`] provides a loop based iteration
//! through messages that are received in a stream over the socket.
//! through messages that are received in a stream over the socket.
//!
//! ## Features
//! The `async` feature exposed by `cargo` allows the socket to use
Expand Down Expand Up @@ -148,7 +148,7 @@ impl NlSocket {
size_of::<u32>() as libc::socklen_t,
)
} {
i if i == 0 => (),
0 => (),
_ => return Err(io::Error::last_os_error()),
}
}
Expand All @@ -167,7 +167,7 @@ impl NlSocket {
size_of::<u32>() as libc::socklen_t,
)
} {
i if i == 0 => (),
0 => (),
_ => return Err(io::Error::last_os_error()),
}
}
Expand Down Expand Up @@ -689,7 +689,7 @@ impl FromRawFd for NlSocketHandle {
}
}

#[cfg(all(feature = "async", not(no_std)))]
#[cfg(feature = "async")]
pub mod tokio {
//! Tokio-specific features for neli
//!
Expand Down

0 comments on commit 163c420

Please sign in to comment.