aboutsummaryrefslogtreecommitdiff
path: root/src/parser.rs
diff options
context:
space:
mode:
authorSimon Thoby <git@nightmared.fr>2023-03-18 20:37:08 +0100
committerSimon Thoby <git@nightmared.fr>2023-03-18 20:37:08 +0100
commit050453d0e63553e80e695579efdfeb183ab1aa7b (patch)
treef4893225bd305fb2b152bcd753d75d24c2ef4802 /src/parser.rs
parent6af23341305d04a22e2e5a8e4e45c99ab502edb4 (diff)
remove the useless trait 'Parsable'
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs62
1 files changed, 22 insertions, 40 deletions
diff --git a/src/parser.rs b/src/parser.rs
index c8667e3..82dd27e 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -170,48 +170,30 @@ pub trait InnerFormat {
) -> Result<DebugStruct<'a, 'b>, std::fmt::Error>;
}
-pub trait Parsable
-where
- Self: Sized,
-{
- fn parse_object(
- buf: &[u8],
- add_obj: u32,
- del_obj: u32,
- ) -> Result<(Self, nfgenmsg, &[u8]), DecodeError>;
-}
-
-impl<T> Parsable for T
-where
- T: AttributeDecoder + Default + Sized,
-{
- fn parse_object(
- buf: &[u8],
- add_obj: u32,
- del_obj: u32,
- ) -> Result<(Self, nfgenmsg, &[u8]), DecodeError> {
- debug!("parse_object() started");
- let (hdr, msg) = parse_nlmsg(buf)?;
-
- let op = get_operation_from_nlmsghdr_type(hdr.nlmsg_type) as u32;
-
- if op != add_obj && op != del_obj {
- return Err(DecodeError::UnexpectedType(hdr.nlmsg_type));
- }
+pub(crate) fn parse_object<T: AttributeDecoder + Default + Sized>(
+ buf: &[u8],
+ add_obj: u32,
+ del_obj: u32,
+) -> Result<(T, nfgenmsg, &[u8]), DecodeError> {
+ debug!("parse_object() started");
+ let (hdr, msg) = parse_nlmsg(buf)?;
+
+ let op = get_operation_from_nlmsghdr_type(hdr.nlmsg_type) as u32;
+
+ if op != add_obj && op != del_obj {
+ return Err(DecodeError::UnexpectedType(hdr.nlmsg_type));
+ }
- let obj_size = hdr.nlmsg_len as usize
- - pad_netlink_object_with_variable_size(size_of::<nlmsghdr>() + size_of::<nfgenmsg>());
+ let obj_size = hdr.nlmsg_len as usize
+ - pad_netlink_object_with_variable_size(size_of::<nlmsghdr>() + size_of::<nfgenmsg>());
- let remaining_data_offset = pad_netlink_object_with_variable_size(hdr.nlmsg_len as usize);
- let remaining_data = &buf[remaining_data_offset..];
+ let remaining_data_offset = pad_netlink_object_with_variable_size(hdr.nlmsg_len as usize);
+ let remaining_data = &buf[remaining_data_offset..];
- let (nfgenmsg, res) = match msg {
- NlMsg::NfGenMsg(nfgenmsg, content) => {
- (nfgenmsg, read_attributes(&content[..obj_size])?)
- }
- _ => return Err(DecodeError::UnexpectedType(hdr.nlmsg_type)),
- };
+ let (nfgenmsg, res) = match msg {
+ NlMsg::NfGenMsg(nfgenmsg, content) => (nfgenmsg, read_attributes(&content[..obj_size])?),
+ _ => return Err(DecodeError::UnexpectedType(hdr.nlmsg_type)),
+ };
- Ok((res, nfgenmsg, remaining_data))
- }
+ Ok((res, nfgenmsg, remaining_data))
}