Skip to content

Commit 1e3eeb4

Browse files
committed
More concise design
1 parent 59ca315 commit 1e3eeb4

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/catalog/loader/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ repository = { workspace = true }
1515
iceberg = { workspace = true }
1616
iceberg-catalog-rest = {workspace = true}
1717
tokio = { workspace = true }
18+
async-trait = {workspace = true}

crates/catalog/loader/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1+
use async_trait::async_trait;
12
use std::collections::HashMap;
23
use std::future::Future;
3-
use std::pin::Pin;
44
use std::sync::Arc;
55

66
use iceberg::{Catalog, CatalogBuilder, Error, ErrorKind, Result};
77
use iceberg_catalog_rest::RestCatalogBuilder;
88

9-
type BoxedCatalogBuilderFuture = Pin<Box<dyn Future<Output = Result<Arc<dyn Catalog>>>>>;
10-
9+
#[async_trait]
1110
pub trait BoxedCatalogBuilder {
12-
fn load(self: Box<Self>, name: String, props: HashMap<String, String>) -> BoxedCatalogBuilderFuture;
11+
async fn load(self: Box<Self>, name: String, props: HashMap<String, String>) -> Result<Arc<dyn Catalog>>;
1312
}
1413

14+
#[async_trait]
1515
impl<T: CatalogBuilder + 'static> BoxedCatalogBuilder for T {
16-
fn load(self: Box<Self>, name: String, props: HashMap<String, String>) -> BoxedCatalogBuilderFuture {
16+
async fn load(self: Box<Self>, name: String, props: HashMap<String, String>) -> Result<Arc<dyn Catalog>> {
1717
let builder = *self;
18-
Box::pin(async move { Ok(Arc::new(builder.load(name, props).await.unwrap()) as Arc<dyn Catalog>) })
18+
Ok(Arc::new(builder.load(name, props).await.unwrap()) as Arc<dyn Catalog>)
1919
}
2020
}
2121

@@ -36,7 +36,7 @@ mod tests {
3636

3737
#[tokio::test]
3838
async fn test_load() {
39-
let mut catalog = load("rest").unwrap();
39+
let catalog = load("rest").unwrap();
4040
catalog.load("rest".to_string(), HashMap::from(
4141
[("key".to_string(), "value".to_string())]
4242
)).await.unwrap();

crates/iceberg/src/catalog/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub trait CatalogBuilder: Default + Debug + Send + Sync {
102102
/// The catalog type that this builder creates.
103103
type C: Catalog;
104104
/// Create a new catalog instance.
105-
fn load(self, name: impl Into<String>, props: HashMap<String, String>) -> impl Future<Output = Result<Self::C>>;
105+
fn load(self, name: impl Into<String>, props: HashMap<String, String>) -> impl Future<Output = Result<Self::C>> + Send;
106106
}
107107

108108
/// NamespaceIdent represents the identifier of a namespace in the catalog.

0 commit comments

Comments
 (0)