Skip to content

Commit

Permalink
Make Gid and Uid implement CopyTo instead of TryCopyTo
Browse files Browse the repository at this point in the history
They were infallible anyway
  • Loading branch information
faern committed Jun 27, 2024
1 parent b1e5d05 commit 96eb102
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/rule/gid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

pub use super::uid::Id;
use crate::{
conversion::TryCopyTo,
conversion::CopyTo,
ffi::pfvar::{pf_rule_gid, PF_OP_NONE},
Result,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand All @@ -28,8 +27,8 @@ impl<T: Into<Id>> From<T> for Gid {
}
}

impl TryCopyTo<pf_rule_gid> for Gid {
fn try_copy_to(&self, pf_rule_gid: &mut pf_rule_gid) -> Result<()> {
impl CopyTo<pf_rule_gid> for Gid {
fn copy_to(&self, pf_rule_gid: &mut pf_rule_gid) {
match self.0 {
Id::Any => {
pf_rule_gid.gid[0] = 0;
Expand All @@ -47,6 +46,5 @@ impl TryCopyTo<pf_rule_gid> for Gid {
pf_rule_gid.op = modifier.into();
}
}
Ok(())
}
}
8 changes: 4 additions & 4 deletions src/rule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ impl TryCopyTo<ffi::pfvar::pf_rule> for FilterRule {
self.from.try_copy_to(&mut pf_rule.src)?;
self.to.try_copy_to(&mut pf_rule.dst)?;
self.label.try_copy_to(&mut pf_rule.label)?;
self.user.try_copy_to(&mut pf_rule.uid)?;
self.group.try_copy_to(&mut pf_rule.gid)?;
self.user.copy_to(&mut pf_rule.uid);
self.group.copy_to(&mut pf_rule.gid);
if let Some(icmp_type) = self.icmp_type {
icmp_type.copy_to(pf_rule);
}
Expand Down Expand Up @@ -232,8 +232,8 @@ impl TryCopyTo<ffi::pfvar::pf_rule> for RedirectRule {
self.from.try_copy_to(&mut pf_rule.src)?;
self.to.try_copy_to(&mut pf_rule.dst)?;
self.label.try_copy_to(&mut pf_rule.label)?;
self.user.try_copy_to(&mut pf_rule.uid)?;
self.group.try_copy_to(&mut pf_rule.gid)?;
self.user.copy_to(&mut pf_rule.uid);
self.group.copy_to(&mut pf_rule.gid);

Ok(())
}
Expand Down
8 changes: 3 additions & 5 deletions src/rule/uid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
// except according to those terms.

use crate::{
conversion::TryCopyTo,
conversion::CopyTo,
ffi::pfvar::{self, pf_rule_uid},
Result,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -40,8 +39,8 @@ impl<T: Into<Id>> From<T> for Uid {
}
}

impl TryCopyTo<pf_rule_uid> for Uid {
fn try_copy_to(&self, pf_rule_uid: &mut pf_rule_uid) -> Result<()> {
impl CopyTo<pf_rule_uid> for Uid {
fn copy_to(&self, pf_rule_uid: &mut pf_rule_uid) {
match self.0 {
Id::Any => {
pf_rule_uid.uid[0] = 0;
Expand All @@ -59,7 +58,6 @@ impl TryCopyTo<pf_rule_uid> for Uid {
pf_rule_uid.op = modifier.into();
}
}
Ok(())
}
}

Expand Down

0 comments on commit 96eb102

Please sign in to comment.