From: Jeff Lucovsky Date: Sat, 22 May 2021 13:41:14 +0000 (-0400) Subject: rust/default: Enable Default usage X-Git-Tag: suricata-7.0.0-beta1~1606 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa8871a5bed5c7d2977f82a392e25e6fced98e8f;p=thirdparty%2Fsuricata.git rust/default: Enable Default usage --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index aa03c8a70e..75a46de9d8 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -88,7 +88,7 @@ macro_rules!export_tx_data_get { } #[repr(C)] -#[derive(Debug,PartialEq,Copy,Clone)] +#[derive(Default,Debug,PartialEq,Copy,Clone)] pub struct AppLayerResult { pub status: i32, pub consumed: u32, @@ -97,20 +97,15 @@ pub struct AppLayerResult { impl AppLayerResult { /// parser has successfully processed in the input, and has consumed all of it - pub fn ok() -> AppLayerResult { - return AppLayerResult { - status: 0, - consumed: 0, - needed: 0, - }; + pub fn ok() -> Self { + Default::default() } /// parser has hit an unrecoverable error. Returning this to the API /// leads to no further calls to the parser. - pub fn err() -> AppLayerResult { - return AppLayerResult { + pub fn err() -> Self { + return Self { status: -1, - consumed: 0, - needed: 0, + ..Default::default() }; } /// parser needs more data. Through 'consumed' it will indicate how many @@ -118,8 +113,8 @@ impl AppLayerResult { /// how many more bytes it needs before getting called again. /// Note: consumed should never be more than the input len /// needed + consumed should be more than the input len - pub fn incomplete(consumed: u32, needed: u32) -> AppLayerResult { - return AppLayerResult { + pub fn incomplete(consumed: u32, needed: u32) -> Self { + return Self { status: 1, consumed: consumed, needed: needed, @@ -362,10 +357,8 @@ pub struct LoggerFlags { impl LoggerFlags { - pub fn new() -> LoggerFlags { - return LoggerFlags{ - flags: 0, - } + pub fn new() -> Self { + Default::default() } pub fn get(&self) -> u32 { diff --git a/rust/src/conf.rs b/rust/src/conf.rs index bc3582f73c..dbb98fafe6 100644 --- a/rust/src/conf.rs +++ b/rust/src/conf.rs @@ -79,8 +79,8 @@ pub struct ConfNode { impl ConfNode { - pub fn wrap(conf: *const c_void) -> ConfNode { - return ConfNode{ + pub fn wrap(conf: *const c_void) -> Self { + return Self { conf: conf, } }