Additional lints

This commit is contained in:
2025-04-04 23:31:17 -06:00
parent 5cc5e1340b
commit f22a283abe
4 changed files with 56 additions and 8 deletions
+16 -2
View File
@@ -7,8 +7,22 @@ edition.workspace = true
license-file.workspace = true
rust-version.workspace = true
[lints]
workspace = true
[lints.rust]
arithmetic_overflow = "forbid"
unsafe_code = "forbid"
[lints.clippy]
arithmetic_side_effects = "deny"
as_conversions = "deny"
checked_conversions = "deny"
default_union_representation = "deny"
expect_used = "deny"
indexing_slicing = "deny"
integer_division = "deny"
integer_division_remainder_used = "deny"
transmute_undefined_repr = "deny"
unchecked_duration_subtraction = "deny"
unwrap_used = "deny"
[dependencies]
ipfilter = { workspace = true, features = ["std"] }
+24 -5
View File
@@ -4,7 +4,7 @@ use std::fs;
use ipfilter::{v4, v6};
use anyhow::Result;
use anyhow::{Context, Result};
use clap::Parser;
use ipnet::{Ipv4Subnets, Ipv6Subnets};
@@ -27,7 +27,16 @@ fn main() -> Result<()> {
for result in reader.records() {
let record = result?;
countries.insert((record[2].to_owned(), record[3].to_owned()));
countries.insert((
record
.get(2)
.context("record is missing index 2")?
.to_owned(),
record
.get(3)
.context("record is missing index 3")?
.to_owned(),
));
}
let mut countries: Vec<_> = countries.drain().collect();
@@ -50,7 +59,7 @@ fn main() -> Result<()> {
let records = reader
.records()
.filter_ok(|r| countries.contains(&r[2]))
.filter_ok(|r| r.get(2).map(|r| countries.contains(r)).unwrap_or(false))
.map(|r| r.map_err(anyhow::Error::from));
macro_rules! merge_ip {
@@ -59,8 +68,18 @@ fn main() -> Result<()> {
.map(|r| {
r.and_then(|record| {
Ok(<$net>::new(
<$addr>::from_bits(record[0].parse()?),
<$addr>::from_bits(record[1].parse()?),
<$addr>::from_bits(
record
.get(0)
.context("record is missing index 0")?
.parse()?,
),
<$addr>::from_bits(
record
.get(1)
.context("record is missing index 1")?
.parse()?,
),
0,
))
})