Skip to content

Commit

Permalink
Merge pull request #32 from agarof/add-copy-hash
Browse files Browse the repository at this point in the history
Add common traits to basic enums
  • Loading branch information
jwhb authored May 16, 2024
2 parents 7d52082 + 890098f commit a503df1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
20 changes: 10 additions & 10 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub struct PayloadField {
pub field: String,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents a protocol layer for `payload` references.
pub enum PayloadBase {
Expand Down Expand Up @@ -161,7 +161,7 @@ pub struct Meta {
pub key: MetaKey,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents a `meta` key for packet meta data.
pub enum MetaKey {
Expand Down Expand Up @@ -203,7 +203,7 @@ pub struct RT {
pub family: Option<RTFamily>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents a key to reference to packet routing data.
pub enum RTKey {
Expand All @@ -212,7 +212,7 @@ pub enum RTKey {
MTU,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents a protocol family for use by the `ct` expression.
pub enum RTFamily {
Expand All @@ -231,15 +231,15 @@ pub struct CT {
pub dir: Option<CTDir>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents a protocol family for use by the `ct` expression.
pub enum CTFamily {
IP,
IP6,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents a direction for use by the `ct` expression.
pub enum CTDir {
Expand All @@ -258,7 +258,7 @@ pub struct Numgen {
pub offset: Option<u32>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents a number generator mode.
pub enum NgMode {
Expand Down Expand Up @@ -296,7 +296,7 @@ pub struct Fib {
pub flags: HashSet<FibFlag>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents which data is queried by `fib` lookup.
pub enum FibResult {
Expand All @@ -305,7 +305,7 @@ pub enum FibResult {
Type,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[serde(rename_all = "lowercase")]
/// Represents flags for `fib` lookup.
pub enum FibFlag {
Expand Down Expand Up @@ -388,7 +388,7 @@ pub struct Osf {
pub ttl: OsfTtl,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// TTL check mode for `osf`.
pub enum OsfTtl {
Expand Down
10 changes: 5 additions & 5 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub enum SetTypeValue {
Concatenated(Vec<SetType>),
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, EnumString)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, EnumString)]
#[serde(rename_all = "lowercase")]
/// Describes a set’s datatype.
pub enum SetType {
Expand Down Expand Up @@ -263,15 +263,15 @@ pub enum SetType {
Ifname,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Describes a set’s policy.
pub enum SetPolicy {
Performance,
Memory,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[serde(rename_all = "lowercase")]
/// Describes a set’s flags.
pub enum SetFlag {
Expand All @@ -281,7 +281,7 @@ pub enum SetFlag {
Dynamic,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Describes an operator on set.
pub enum SetOp {
Expand Down Expand Up @@ -373,7 +373,7 @@ pub struct Limit {
pub inv: Option<bool>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum LimitUnit {
Packets,
Expand Down
18 changes: 9 additions & 9 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub struct FWD {
pub addr: Option<Expression>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Protocol family for `FWD`.
pub enum FWDFamily {
Expand Down Expand Up @@ -223,15 +223,15 @@ pub struct NAT {
pub flags: Option<HashSet<NATFlag>>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Protocol family for `NAT`.
pub enum NATFamily {
IP,
IP6,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[serde(rename_all = "lowercase")]
/// Flags for `NAT`.
pub enum NATFlag {
Expand All @@ -258,7 +258,7 @@ impl Reject {
}
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Types of `Reject`.
pub enum RejectType {
Expand All @@ -280,7 +280,7 @@ pub struct Set {
pub set: String,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Operators on `Set`.
pub enum SetOp {
Expand Down Expand Up @@ -334,7 +334,7 @@ impl Log {
}
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Levels of `Log`.
pub enum LogLevel {
Expand All @@ -349,7 +349,7 @@ pub enum LogLevel {
Audit,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, Hash, EnumString)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Hash, EnumString)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
/// Flags of `Log`.
Expand Down Expand Up @@ -389,7 +389,7 @@ pub struct Queue {
pub flags: Option<HashSet<QueueFlag>>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Hash)]
#[serde(rename_all = "lowercase")]
/// Flags of `Queue`.
pub enum QueueFlag {
Expand Down Expand Up @@ -420,7 +420,7 @@ pub struct CTCount {
pub inv: Option<bool>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
/// Represents an operator for `Match`.
pub enum Operator {
#[serde(rename = "&")]
Expand Down
12 changes: 6 additions & 6 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
/// Families in nftables.
///
/// See <https://wiki.nftables.org/wiki-nftables/index.php/Nftables_families>.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum NfFamily {
IP,
Expand All @@ -14,7 +14,7 @@ pub enum NfFamily {
NetDev,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents the type of a Chain.
pub enum NfChainType {
Expand All @@ -23,15 +23,15 @@ pub enum NfChainType {
NAT,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents the policy of a Chain.
pub enum NfChainPolicy {
Accept,
Drop,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents a netfilter hook.
///
Expand All @@ -46,7 +46,7 @@ pub enum NfHook {
Egress,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents a conntrack helper protocol.
pub enum CTHProto {
Expand All @@ -60,7 +60,7 @@ pub enum CTHProto {
Generic,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum RejectCode {
#[serde(rename = "admin-prohibited")]
/// Host administratively prohibited (ICMPX, ICMP, ICMPv6)
Expand Down

0 comments on commit a503df1

Please sign in to comment.