Skip to content

Commit

Permalink
rust/default: Enable Default usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jlucovsky committed May 22, 2021
1 parent 3f9879c commit 91a8a25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
27 changes: 10 additions & 17 deletions rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -97,29 +97,24 @@ 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
/// of the input bytes it has consumed. Through 'needed' it will indicate
/// 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,
Expand Down Expand Up @@ -358,10 +353,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 {
Expand Down
4 changes: 2 additions & 2 deletions rust/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 91a8a25

Please sign in to comment.