mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2025-07-16 22:13:30 +02:00
Make clippy happy
Mostly cleaning up type system crimes from when I was still learning rust: * Abuse of `match` and loops * Non-use of helper functions (`is_empty`, `is_none`) * Use of borrowed owned types (`&String`) * Implementing `Into` instead of `From`
This commit is contained in:
19
src/geoip.rs
19
src/geoip.rs
@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
use log::{info,warn,error};
|
||||
use maxminddb;
|
||||
use maxminddb::geoip2;
|
||||
|
||||
use parking_lot::RwLock;
|
||||
@ -56,7 +55,7 @@ pub struct MMDBCarrier {
|
||||
}
|
||||
|
||||
pub trait QueryLocation {
|
||||
fn query_location_for_ip(&self, address: &IpAddr, laguages: &Vec<&String>) -> Option<LocationResult>;
|
||||
fn query_location_for_ip(&self, address: &IpAddr, laguages: &[&str]) -> Option<LocationResult>;
|
||||
}
|
||||
|
||||
pub trait QueryAsn {
|
||||
@ -67,12 +66,12 @@ pub trait QueryAsn {
|
||||
|
||||
pub fn extract_localized_name(
|
||||
names: &Option<BTreeMap<&str, &str>>,
|
||||
languages: &Vec<&String>)
|
||||
languages: &[&str])
|
||||
-> Option<String> {
|
||||
match names {
|
||||
Some(names) => {
|
||||
for language in languages {
|
||||
if let Some(name) = names.get(language.as_str()){
|
||||
if let Some(name) = names.get(language){
|
||||
return Some(name.to_string())
|
||||
}
|
||||
}
|
||||
@ -82,7 +81,7 @@ names: &Option<BTreeMap<&str, &str>>,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_city_to_named_location(item: geoip2::city::City, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_city_to_named_location(item: geoip2::city::City, languages: &[&str]) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: None,
|
||||
geoname_id: item.geoname_id,
|
||||
@ -90,7 +89,7 @@ pub fn geoip2_city_to_named_location(item: geoip2::city::City, languages: &Vec<&
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_continent_to_named_location(item: geoip2::country::Continent, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_continent_to_named_location(item: geoip2::country::Continent, languages: &[&str]) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: item.code.map(ToString::to_string),
|
||||
geoname_id: item.geoname_id,
|
||||
@ -98,7 +97,7 @@ pub fn geoip2_continent_to_named_location(item: geoip2::country::Continent, lang
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_country_to_named_location(item: geoip2::country::Country, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_country_to_named_location(item: geoip2::country::Country, languages: &[&str]) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: item.iso_code.map(ToString::to_string),
|
||||
geoname_id: item.geoname_id,
|
||||
@ -106,7 +105,7 @@ pub fn geoip2_country_to_named_location(item: geoip2::country::Country, language
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_represented_country_to_named_location(item: geoip2::country::RepresentedCountry, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_represented_country_to_named_location(item: geoip2::country::RepresentedCountry, languages: &[&str]) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: item.iso_code.map(ToString::to_string),
|
||||
geoname_id: item.geoname_id,
|
||||
@ -114,7 +113,7 @@ pub fn geoip2_represented_country_to_named_location(item: geoip2::country::Repre
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_subdivision_to_named_location(item: geoip2::city::Subdivision, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_subdivision_to_named_location(item: geoip2::city::Subdivision, languages: &[&str]) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: item.iso_code.map(ToString::to_string),
|
||||
geoname_id: item.geoname_id,
|
||||
@ -148,7 +147,7 @@ impl QueryAsn for MMDBCarrier {
|
||||
}
|
||||
|
||||
impl QueryLocation for MMDBCarrier {
|
||||
fn query_location_for_ip(&self, address: &IpAddr, languages: &Vec<&String>) -> Option<LocationResult> {
|
||||
fn query_location_for_ip(&self, address: &IpAddr, languages: &[&str]) -> Option<LocationResult> {
|
||||
let mmdb = self.mmdb.read();
|
||||
match &*mmdb {
|
||||
Some(mmdb) => {
|
||||
|
Reference in New Issue
Block a user