Skip to content

Commit

Permalink
turn Log in a struct to group future arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
lafleurdeboum committed Sep 28, 2021
1 parent d2c9bc7 commit 8befa0b
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions nftnl/src/expr/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ use nftnl_sys::{
};

/// A log expression.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum Log {
NoGroup,
Group(LogGroup),
pub struct Log {
group: Option<LogGroup>,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
Expand All @@ -25,11 +23,8 @@ pub enum LogGroup {


impl Log {
pub fn new() -> Self {
Log::NoGroup
}
pub fn new_with_group(group: LogGroup) -> Self {
Log::Group(group)
pub fn new(group: Option<LogGroup>) -> Self {
Log { group }
}
}

Expand All @@ -39,16 +34,13 @@ impl Expression for Log {
let expr = try_alloc!(sys::nftnl_expr_alloc(
b"log\0" as *const _ as *const c_char
));
match self {
Log::NoGroup => (),
Log::Group(group) => {
sys::nftnl_expr_set_u32(
expr,
sys::NFTNL_EXPR_LOG_GROUP as u16,
*group as u32,
);
}
}
if let Some(group) = self.group {
sys::nftnl_expr_set_u32(
expr,
sys::NFTNL_EXPR_LOG_GROUP as u16,
group as u32,
);
};
expr
}
}
Expand All @@ -57,9 +49,9 @@ impl Expression for Log {
#[macro_export]
macro_rules! nft_expr_log {
(group $group:ident) => {
$crate::expr::Log::new_with_group($group)
$crate::expr::Log::new($group, None)
};
() => {
$crate::expr::Log::new()
$crate::expr::Log::new(None)
};
}

0 comments on commit 8befa0b

Please sign in to comment.