Skip to content

Commit

Permalink
Merge pull request #1909 from dtolnay-contrib/asynctrait
Browse files Browse the repository at this point in the history
Use Rust 1.75's async fn in trait instead of #[async_trait]
  • Loading branch information
Manishearth authored Jan 9, 2024
2 parents 7e76e17 + 6f8bf67 commit 3db12c8
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::error::Error;
use std::future::Future;
use std::sync::Arc;
use std::time::Instant;

Expand All @@ -10,10 +11,9 @@ const CACHE_TTL_SECS: u64 = 120;

pub type Cache<T> = State<Arc<RwLock<T>>>;

#[async_trait]
pub trait Cached: Send + Sync + Clone + 'static {
fn get_timestamp(&self) -> Instant;
async fn fetch() -> Result<Self, Box<dyn Error + Send + Sync>>;
fn fetch() -> impl Future<Output = Result<Self, Box<dyn Error + Send + Sync>>> + Send;
async fn get(cache: &Cache<Self>) -> Self {
let cached = cache.read().await.clone();
let timestamp = cached.get_timestamp();
Expand Down
2 changes: 0 additions & 2 deletions src/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ impl Default for RustVersion {
}
}

#[async_trait]
impl Cached for RustVersion {
fn get_timestamp(&self) -> Instant {
self.1
Expand All @@ -68,7 +67,6 @@ impl Default for RustReleasePost {
}
}

#[async_trait]
impl Cached for RustReleasePost {
fn get_timestamp(&self) -> Instant {
self.1
Expand Down
1 change: 0 additions & 1 deletion src/teams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ impl Default for RustTeams {
}
}

#[async_trait]
impl Cached for RustTeams {
fn get_timestamp(&self) -> Instant {
self.1
Expand Down

0 comments on commit 3db12c8

Please sign in to comment.