Skip to content

Commit

Permalink
Add: Implement Display trait for Category
Browse files Browse the repository at this point in the history
This allows to convert the category directly to a string.
  • Loading branch information
jjnicola committed Nov 23, 2022
1 parent 2a69259 commit 263411f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
20 changes: 19 additions & 1 deletion rust/nvtcache/src/nvt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::dberror::DbError;
use crate::dberror::Result;
use std::collections::LinkedList;
use std::fmt;

///Alias for time stamps
type TimeT = i64;
Expand All @@ -20,6 +20,24 @@ pub enum Category {
ActEnd,
}

impl fmt::Display for Category {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Category::ActInit => write!(f, "0"),
Category::ActScanner => write!(f, "1"),
Category::ActSettings => write!(f, "2"),
Category::ActGatherInfo => write!(f, "3"),
Category::ActAttack => write!(f, "4"),
Category::ActMixedAttack => write!(f, "5"),
Category::ActDestructiveAttack => write!(f, "6"),
Category::ActDenial => write!(f, "7"),
Category::ActKillHost => write!(f, "8"),
Category::ActFlood => write!(f, "9"),
Category::ActEnd => write!(f, "10"),
}
}
}

/// Structure to store NVT preferences
#[derive(Debug)]
pub struct NvtPref {
Expand Down
9 changes: 8 additions & 1 deletion rust/nvtcache/tests/nvt_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use nvtcache::dberror::Result;
use nvtcache::nvt::{Nvt, NvtRef};
use nvtcache::nvt::{Category, Nvt, NvtRef};

#[cfg(test)]
mod test {
Expand Down Expand Up @@ -105,4 +105,11 @@ mod test {

Ok(())
}

#[test]
fn test_category_from_trait() {
let cat = Category::ActEnd;

assert_eq!(cat.to_string(), "10");
}
}

0 comments on commit 263411f

Please sign in to comment.