1
1
use std:: future:: Future ;
2
+ use std:: pin:: Pin ;
2
3
use std:: sync:: Arc ;
3
4
4
5
use iceberg:: { Catalog , CatalogBuilder , Error , ErrorKind , Result } ;
5
6
use iceberg_catalog_rest:: RestCatalogBuilder ;
6
7
8
+ type BoxedCatalogBuilderFuture = Pin < Box < dyn Future < Output = Result < Arc < dyn Catalog > > > > > ;
9
+
7
10
pub trait BoxedCatalogBuilder {
8
11
fn name ( & mut self , name : String ) ;
9
12
fn uri ( & mut self , uri : String ) ;
10
13
fn warehouse ( & mut self , warehouse : String ) ;
11
14
fn with_prop ( & mut self , key : String , value : String ) ;
12
15
13
- fn build ( self : Box < Self > ) -> Box < dyn Future < Output = Result < Arc < dyn Catalog > > > > ;
16
+ fn build ( self : Box < Self > ) -> BoxedCatalogBuilderFuture ;
14
17
}
15
18
16
19
impl < T : CatalogBuilder + ' static > BoxedCatalogBuilder for T {
@@ -30,9 +33,9 @@ impl<T: CatalogBuilder + 'static> BoxedCatalogBuilder for T {
30
33
self . with_prop ( key, value) ;
31
34
}
32
35
33
- fn build ( self : Box < Self > ) -> Box < dyn Future < Output = Result < Arc < dyn Catalog > > > > {
36
+ fn build ( self : Box < Self > ) -> BoxedCatalogBuilderFuture {
34
37
let builder = * self ;
35
- Box :: new ( async move { Ok ( Arc :: new ( builder. build ( ) . await . unwrap ( ) ) as Arc < dyn Catalog > ) } )
38
+ Box :: pin ( async move { Ok ( Arc :: new ( builder. build ( ) . await . unwrap ( ) ) as Arc < dyn Catalog > ) } )
36
39
}
37
40
}
38
41
@@ -45,3 +48,17 @@ pub fn load(r#type: &str) -> Result<Box<dyn BoxedCatalogBuilder>> {
45
48
) ) ,
46
49
}
47
50
}
51
+
52
+ #[ cfg( test) ]
53
+ mod tests {
54
+ use crate :: load;
55
+
56
+ #[ tokio:: test]
57
+ async fn test_load ( ) {
58
+ let mut catalog = load ( "rest" ) . unwrap ( ) ;
59
+ catalog. name ( "rest" . to_string ( ) ) ;
60
+ catalog. with_prop ( "key" . to_string ( ) , "value" . to_string ( ) ) ;
61
+
62
+ catalog. build ( ) . await . unwrap ( ) ;
63
+ }
64
+ }
0 commit comments