Skip to content

Commit a22ab6d

Browse files
vsilentCopilot
andcommitted
fix: remove redundant to_string() in format! args
NfTable implements Display, so format! uses it directly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent db9e5c0 commit a22ab6d

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

src/firewall/nftables.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl NfTablesBackend {
9696
/// Create a table
9797
pub fn create_table(&self, table: &NfTable) -> Result<()> {
9898
let output = Command::new("nft")
99-
.args(["add", "table", &table.to_string()])
99+
.args(["add", "table", &table])
100100
.output()
101101
.context("Failed to create nftables table")?;
102102

@@ -113,7 +113,7 @@ impl NfTablesBackend {
113113
/// Delete a table
114114
pub fn delete_table(&self, table: &NfTable) -> Result<()> {
115115
let output = Command::new("nft")
116-
.args(["delete", "table", &table.to_string()])
116+
.args(["delete", "table", &table])
117117
.output()
118118
.context("Failed to delete nftables table")?;
119119

@@ -131,9 +131,7 @@ impl NfTablesBackend {
131131
pub fn create_chain(&self, chain: &NfChain) -> Result<()> {
132132
let cmd = format!(
133133
"add chain {} {} {{ type {} hook input priority 0; }}",
134-
chain.table.to_string(),
135-
chain.name,
136-
chain.chain_type
134+
chain.table, chain.name, chain.chain_type
137135
);
138136

139137
let output = Command::new("nft")
@@ -153,7 +151,7 @@ impl NfTablesBackend {
153151

154152
/// Delete a chain
155153
pub fn delete_chain(&self, chain: &NfChain) -> Result<()> {
156-
let cmd = format!("delete chain {} {}", chain.table.to_string(), chain.name);
154+
let cmd = format!("delete chain {} {}", chain.table, chain.name);
157155

158156
let output = Command::new("nft")
159157
.args(["-c", &cmd])
@@ -174,9 +172,7 @@ impl NfTablesBackend {
174172
pub fn add_rule(&self, rule: &NfRule) -> Result<()> {
175173
let cmd = format!(
176174
"add rule {} {} {}",
177-
rule.chain.table.to_string(),
178-
rule.chain.name,
179-
rule.rule_spec
175+
rule.chain.table, rule.chain.name, rule.rule_spec
180176
);
181177

182178
let output = Command::new("nft")
@@ -198,9 +194,7 @@ impl NfTablesBackend {
198194
pub fn delete_rule(&self, rule: &NfRule) -> Result<()> {
199195
let cmd = format!(
200196
"delete rule {} {} {}",
201-
rule.chain.table.to_string(),
202-
rule.chain.name,
203-
rule.rule_spec
197+
rule.chain.table, rule.chain.name, rule.rule_spec
204198
);
205199

206200
let output = Command::new("nft")
@@ -228,7 +222,7 @@ impl NfTablesBackend {
228222

229223
/// Flush a chain
230224
pub fn flush_chain(&self, chain: &NfChain) -> Result<()> {
231-
let cmd = format!("flush chain {} {}", chain.table.to_string(), chain.name);
225+
let cmd = format!("flush chain {} {}", chain.table, chain.name);
232226

233227
let output = Command::new("nft")
234228
.args(["-c", &cmd])
@@ -247,7 +241,7 @@ impl NfTablesBackend {
247241

248242
/// List rules in a chain
249243
pub fn list_rules(&self, chain: &NfChain) -> Result<Vec<String>> {
250-
let cmd = format!("list chain {} {}", chain.table.to_string(), chain.name);
244+
let cmd = format!("list chain {} {}", chain.table, chain.name);
251245

252246
let output = Command::new("nft")
253247
.args(["-c", &cmd])

0 commit comments

Comments
 (0)