@@ -160,61 +160,55 @@ impl ObjectStoreBuilder {
160160 ObjectStoreKind :: Local => ObjectStoreImpl :: Local ( LocalFileSystem :: new ( ) ) ,
161161 ObjectStoreKind :: InMemory => ObjectStoreImpl :: InMemory ( InMemory :: new ( ) ) ,
162162 ObjectStoreKind :: Azure => {
163- let maybe_store = MicrosoftAzureBuilder :: new ( )
163+ let store = MicrosoftAzureBuilder :: new ( )
164164 . with_url ( url. clone ( ) )
165165 . try_with_options ( & self . options ) ?
166166 . with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
167167 . with_retry ( self . retry_config . clone ( ) . unwrap_or_default ( ) )
168- . build ( ) ;
169- if let Ok ( store) = maybe_store {
170- ObjectStoreImpl :: Azrue ( store)
171- } else {
172- let store = MicrosoftAzureBuilder :: from_env ( )
173- . with_url ( url. clone ( ) )
174- . try_with_options ( & self . options ) ?
175- . with_client_options ( self . client_options . unwrap_or_default ( ) )
176- . with_retry ( self . retry_config . unwrap_or_default ( ) )
177- . build ( ) ?;
178- ObjectStoreImpl :: Azrue ( store)
179- }
168+ . build ( )
169+ . or_else ( |_| {
170+ MicrosoftAzureBuilder :: from_env ( )
171+ . with_url ( url. clone ( ) )
172+ . try_with_options ( & self . options ) ?
173+ . with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
174+ . with_retry ( self . retry_config . clone ( ) . unwrap_or_default ( ) )
175+ . build ( )
176+ } ) ?;
177+ ObjectStoreImpl :: Azrue ( store)
180178 }
181179 ObjectStoreKind :: S3 => {
182- let maybe_store = AmazonS3Builder :: new ( )
180+ let store = AmazonS3Builder :: new ( )
183181 . with_url ( url. clone ( ) )
184182 . try_with_options ( & self . options ) ?
185183 . with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
186184 . with_retry ( self . retry_config . clone ( ) . unwrap_or_default ( ) )
187- . build ( ) ;
188- if let Ok ( store) = maybe_store {
189- ObjectStoreImpl :: S3 ( store)
190- } else {
191- let store = AmazonS3Builder :: from_env ( )
192- . with_url ( url. clone ( ) )
193- . try_with_options ( & self . options ) ?
194- . with_client_options ( self . client_options . unwrap_or_default ( ) )
195- . with_retry ( self . retry_config . unwrap_or_default ( ) )
196- . build ( ) ?;
197- ObjectStoreImpl :: S3 ( store)
198- }
185+ . build ( )
186+ . or_else ( |_| {
187+ AmazonS3Builder :: from_env ( )
188+ . with_url ( url. clone ( ) )
189+ . try_with_options ( & self . options ) ?
190+ . with_client_options ( self . client_options . unwrap_or_default ( ) )
191+ . with_retry ( self . retry_config . unwrap_or_default ( ) )
192+ . build ( )
193+ } ) ?;
194+ ObjectStoreImpl :: S3 ( store)
199195 }
200196 ObjectStoreKind :: Google => {
201- let maybe_store = GoogleCloudStorageBuilder :: new ( )
197+ let store = GoogleCloudStorageBuilder :: new ( )
202198 . with_url ( url. clone ( ) )
203199 . try_with_options ( & self . options ) ?
204200 . with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
205201 . with_retry ( self . retry_config . clone ( ) . unwrap_or_default ( ) )
206- . build ( ) ;
207- if let Ok ( store) = maybe_store {
208- ObjectStoreImpl :: Gcp ( store)
209- } else {
210- let store = GoogleCloudStorageBuilder :: from_env ( )
211- . with_url ( url. clone ( ) )
212- . try_with_options ( & self . options ) ?
213- . with_client_options ( self . client_options . unwrap_or_default ( ) )
214- . with_retry ( self . retry_config . unwrap_or_default ( ) )
215- . build ( ) ?;
216- ObjectStoreImpl :: Gcp ( store)
217- }
202+ . build ( )
203+ . or_else ( |_| {
204+ GoogleCloudStorageBuilder :: from_env ( )
205+ . with_url ( url. clone ( ) )
206+ . try_with_options ( & self . options ) ?
207+ . with_client_options ( self . client_options . unwrap_or_default ( ) )
208+ . with_retry ( self . retry_config . unwrap_or_default ( ) )
209+ . build ( )
210+ } ) ?;
211+ ObjectStoreImpl :: Gcp ( store)
218212 }
219213 } ;
220214
0 commit comments