Skip to content

Commit 5e27c4e

Browse files
committed
feat(server): remove async trait
1 parent 0b81c63 commit 5e27c4e

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

server/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2121

2222
- `memory-item-search` feature ([#322](https://github.com/stac-utils/stac-rs/pull/322))
2323
- `APPLICATION_GEO_JSON` and `APPLICATION_OPENAPI_3_0` constants (they're now in `stac::mime`) ([#327](https://github.com/stac-utils/stac-rs/pull/327))
24+
- `async_trait` ([#347](https://github.com/stac-utils/stac-rs/pull/347))
2425

2526
## [0.1.1] - 2024-08-12
2627

server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ repository = "https://github.com/stac-utils/stac-rs"
99
license = "MIT OR Apache-2.0"
1010
keywords = ["geospatial", "stac", "metadata", "geo", "raster"]
1111
categories = ["science", "data-structures"]
12+
rust-version = "1.75"
1213

1314
[features]
1415
axum = ["dep:axum", "dep:bytes", "dep:mime", "dep:tower-http"]
1516
pgstac = ["dep:pgstac", "dep:bb8", "dep:bb8-postgres", "dep:tokio-postgres"]
1617

1718
[dependencies]
18-
async-trait = "0.1"
1919
axum = { version = "0.7", optional = true }
2020
bb8 = { version = "0.8", optional = true }
2121
bb8-postgres = { version = "0.8", optional = true }

server/src/backend/memory.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{Backend, Error, Result, DEFAULT_LIMIT};
2-
use async_trait::async_trait;
32
use serde_json::Map;
43
use stac::{Collection, Item};
54
use stac_api::{ItemCollection, Items, Search};
@@ -34,7 +33,6 @@ impl MemoryBackend {
3433
}
3534
}
3635

37-
#[async_trait]
3836
impl Backend for MemoryBackend {
3937
fn has_item_search(&self) -> bool {
4038
true

server/src/backend/mod.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ mod memory;
33
mod pgstac;
44

55
use crate::Result;
6-
use async_trait::async_trait;
76
pub use memory::MemoryBackend;
87
#[cfg(feature = "pgstac")]
98
pub use pgstac::PgstacBackend;
109
use stac::{Collection, Item};
1110
use stac_api::{ItemCollection, Items, Search};
11+
use std::future::Future;
1212

1313
/// Storage backend for a STAC API.
14-
#[async_trait]
1514
pub trait Backend: Clone + Sync + Send + 'static {
1615
/// Returns true if this backend has item search capabilities.
1716
///
@@ -36,7 +35,7 @@ pub trait Backend: Clone + Sync + Send + 'static {
3635
/// assert!(collections.is_empty());
3736
/// # })
3837
/// ```
39-
async fn collections(&self) -> Result<Vec<Collection>>;
38+
fn collections(&self) -> impl Future<Output = Result<Vec<Collection>>> + Send;
4039

4140
/// Returns a single collection.
4241
///
@@ -50,7 +49,7 @@ pub trait Backend: Clone + Sync + Send + 'static {
5049
/// assert!(collection.is_none());
5150
/// # })
5251
/// ```
53-
async fn collection(&self, id: &str) -> Result<Option<Collection>>;
52+
fn collection(&self, id: &str) -> impl Future<Output = Result<Option<Collection>>> + Send;
5453

5554
/// Adds a collection.
5655
///
@@ -65,7 +64,8 @@ pub trait Backend: Clone + Sync + Send + 'static {
6564
/// backend.add_collection(Collection::new("an-id", "a description")).await.unwrap();
6665
/// # })
6766
/// ```
68-
async fn add_collection(&mut self, collection: Collection) -> Result<()>;
67+
fn add_collection(&mut self, collection: Collection)
68+
-> impl Future<Output = Result<()>> + Send;
6969

7070
/// Adds an item.
7171
///
@@ -86,7 +86,7 @@ pub trait Backend: Clone + Sync + Send + 'static {
8686
/// backend.add_item(Item::new("item-id").collection("collection-id")).await.unwrap();
8787
/// # })
8888
/// ```
89-
async fn add_item(&mut self, item: Item) -> Result<()>;
89+
fn add_item(&mut self, item: Item) -> impl Future<Output = Result<()>> + Send;
9090

9191
/// Retrieves items for a given collection.
9292
///
@@ -104,7 +104,11 @@ pub trait Backend: Clone + Sync + Send + 'static {
104104
/// let items = backend.items("collection-id", Items::default()).await.unwrap();
105105
/// # })
106106
/// ```
107-
async fn items(&self, collection_id: &str, items: Items) -> Result<Option<ItemCollection>>;
107+
fn items(
108+
&self,
109+
collection_id: &str,
110+
items: Items,
111+
) -> impl Future<Output = Result<Option<ItemCollection>>> + Send;
108112

109113
/// Retrieves an item from a collection.
110114
///
@@ -121,7 +125,11 @@ pub trait Backend: Clone + Sync + Send + 'static {
121125
/// let item = backend.item("collection-id", "item-id").await.unwrap().unwrap();
122126
/// # })
123127
/// ```
124-
async fn item(&self, collection_id: &str, item_id: &str) -> Result<Option<Item>>;
128+
fn item(
129+
&self,
130+
collection_id: &str,
131+
item_id: &str,
132+
) -> impl Future<Output = Result<Option<Item>>> + Send;
125133

126134
/// Searches a backend.
127135
///
@@ -136,5 +144,5 @@ pub trait Backend: Clone + Sync + Send + 'static {
136144
/// let item_collection = backend.search(Search::default()).await.unwrap();
137145
/// # })
138146
/// ```
139-
async fn search(&self, search: Search) -> Result<ItemCollection>;
147+
fn search(&self, search: Search) -> impl Future<Output = Result<ItemCollection>> + Send;
140148
}

server/src/backend/pgstac.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{Backend, Error, Result};
2-
use async_trait::async_trait;
32
use bb8::Pool;
43
use bb8_postgres::PostgresConnectionManager;
54
use pgstac::Client;
@@ -36,7 +35,6 @@ impl PgstacBackend {
3635
}
3736
}
3837

39-
#[async_trait]
4038
impl Backend for PgstacBackend {
4139
fn has_item_search(&self) -> bool {
4240
true

0 commit comments

Comments
 (0)