@@ -4,11 +4,9 @@ use std::time::Duration;
44
55use bytes:: Bytes ;
66use futures_util:: stream:: BoxStream ;
7- use objectstore_types:: ExpirationPolicy ;
7+ use objectstore_types:: { Compression , ExpirationPolicy , scope } ;
88use url:: Url ;
99
10- pub use objectstore_types:: { Compression , scope as scope_types} ;
11-
1210const USER_AGENT : & str = concat ! ( "objectstore-client/" , env!( "CARGO_PKG_VERSION" ) ) ;
1311
1412#[ derive( Debug ) ]
@@ -205,20 +203,20 @@ impl Usecase {
205203 }
206204
207205 /// Creates a new [`Scope`] tied to the given organization.
208- pub fn for_organization ( & self , organization : u64 ) -> crate :: Result < Scope > {
206+ pub fn for_organization ( & self , organization : u64 ) -> Scope {
209207 Scope :: for_organization ( self . clone ( ) , organization)
210208 }
211209
212210 /// Creates a new [`Scope`] tied to the given organization and project.
213- pub fn for_project ( & self , organization : u64 , project : u64 ) -> crate :: Result < Scope > {
211+ pub fn for_project ( & self , organization : u64 , project : u64 ) -> Scope {
214212 Scope :: for_project ( self . clone ( ) , organization, project)
215213 }
216214}
217215
218216#[ derive( Debug ) ]
219217pub ( crate ) struct ScopeInner {
220218 usecase : Usecase ,
221- scopes : scope_types :: Scopes ,
219+ scopes : scope :: Scopes ,
222220}
223221
224222impl ScopeInner {
@@ -260,28 +258,23 @@ impl Scope {
260258 pub fn new ( usecase : Usecase ) -> Self {
261259 Self ( Ok ( ScopeInner {
262260 usecase,
263- scopes : scope_types :: Scopes :: empty ( ) ,
261+ scopes : scope :: Scopes :: empty ( ) ,
264262 } ) )
265263 }
266264
267- fn for_organization ( usecase : Usecase , organization : u64 ) -> crate :: Result < Self > {
268- let scopes = scope_types:: Scopes :: from_iter ( [ scope_types:: Scope :: create (
269- "org" ,
270- & organization. to_string ( ) ,
271- ) ?] ) ;
272- Ok ( Self ( Ok ( ScopeInner { usecase, scopes } ) ) )
265+ fn for_organization ( usecase : Usecase , organization : u64 ) -> Self {
266+ Self :: new ( usecase) . push ( "org" , organization)
273267 }
274268
275- fn for_project ( usecase : Usecase , organization : u64 , project : u64 ) -> crate :: Result < Self > {
276- let scopes = scope_types:: Scopes :: from_iter ( [
277- scope_types:: Scope :: create ( "org" , & organization. to_string ( ) ) ?,
278- scope_types:: Scope :: create ( "project" , & project. to_string ( ) ) ?,
279- ] ) ;
280- Ok ( Self ( Ok ( ScopeInner { usecase, scopes } ) ) )
269+ fn for_project ( usecase : Usecase , organization : u64 , project : u64 ) -> Self {
270+ Self :: for_organization ( usecase, organization) . push ( "project" , project)
281271 }
282272
283273 /// Extends this Scope by creating a new sub-scope nested within it.
284- pub fn push ( self , key : & str , value : & str ) -> Self {
274+ pub fn push < V > ( self , key : & str , value : V ) -> Self
275+ where
276+ V : std:: fmt:: Display ,
277+ {
285278 let result = self . 0 . and_then ( |mut inner| {
286279 inner. scopes . push ( key, value) ?;
287280 Ok ( inner)
@@ -434,7 +427,6 @@ mod tests {
434427 let usecase = Usecase :: new ( "testing" ) ;
435428 let scope = usecase
436429 . for_project ( 12345 , 1337 )
437- . unwrap ( )
438430 . push ( "app_slug" , "email_app" ) ;
439431 let session = client. session ( scope) . unwrap ( ) ;
440432
@@ -448,7 +440,7 @@ mod tests {
448440 fn test_object_url_with_base_path ( ) {
449441 let client = Client :: new ( "http://127.0.0.1:8888/api/prefix" ) . unwrap ( ) ;
450442 let usecase = Usecase :: new ( "testing" ) ;
451- let scope = usecase. for_project ( 12345 , 1337 ) . unwrap ( ) ;
443+ let scope = usecase. for_project ( 12345 , 1337 ) ;
452444 let session = client. session ( scope) . unwrap ( ) ;
453445
454446 assert_eq ! (
0 commit comments