From 52382d83d90339d19770133f24b0f566c6a64a07 Mon Sep 17 00:00:00 2001 From: lafleur Date: Tue, 28 Sep 2021 22:10:51 +0200 Subject: [PATCH] fixes #45 - turn Log in a struct to group future arguments --- nftnl/src/expr/log.rs | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/nftnl/src/expr/log.rs b/nftnl/src/expr/log.rs index 236735c..9f2f052 100644 --- a/nftnl/src/expr/log.rs +++ b/nftnl/src/expr/log.rs @@ -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, } #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] @@ -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) -> Self { + Log { group } } } @@ -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 } } @@ -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) }; () => { - $crate::expr::Log::new() + $crate::expr::Log::new(None) }; }