i3status-rust
i3status-rust copied to clipboard
Add global geolocator
Resolves #2075
TODO
- [x] Add documentation
We don't need async_trait here :)
diff --git a/src/locator.rs b/src/locator.rs
index 9aa6b9773..f5ebd654a 100644
--- a/src/locator.rs
+++ b/src/locator.rs
@@ -1,10 +1,10 @@
use crate::errors::{Error, ErrorContext, Result, StdError};
use std::borrow::Cow;
use std::fmt;
+use std::future::Future;
use std::sync::{Arc, LazyLock, Mutex};
use std::time::{Duration, Instant};
-use async_trait::async_trait;
use serde::Deserialize;
use smart_default::SmartDefault;
@@ -82,18 +82,16 @@ pub enum LocatorDriver {
Ip2Location,
}
-#[async_trait]
pub trait Backend {
fn name(&self) -> Cow<'static, str>;
- async fn get_info(
+ fn get_info(
&self,
client: &reqwest::Client,
api_key: &Option<String>,
- ) -> Result<IPAddressInfo>;
+ ) -> impl Future<Output = Result<IPAddressInfo>>;
}
-#[async_trait]
impl Backend for LocatorDriver {
fn name(&self) -> Cow<'static, str> {
match self {
diff --git a/src/locator/ip2location.rs b/src/locator/ip2location.rs
index e4b998c83..b7019075f 100644
--- a/src/locator/ip2location.rs
+++ b/src/locator/ip2location.rs
@@ -185,7 +185,6 @@ impl StdError for ApiError {}
#[derive(Deserialize, Debug, Default, Clone)]
pub struct Ip2Location;
-#[async_trait]
impl Backend for Ip2Location {
fn name(&self) -> Cow<'static, str> {
Cow::Borrowed("ip2location.io")
diff --git a/src/locator/ipapi.rs b/src/locator/ipapi.rs
index 898b4bf70..7e9bbfe02 100644
--- a/src/locator/ipapi.rs
+++ b/src/locator/ipapi.rs
@@ -90,7 +90,6 @@ impl StdError for ApiError {}
#[derive(Deserialize, Debug, Default, Clone)]
pub struct Ipapi;
-#[async_trait]
impl Backend for Ipapi {
fn name(&self) -> Cow<'static, str> {
Cow::Borrowed("ipapi.co")
fixed merge conflict