@@ -160,61 +160,55 @@ impl ObjectStoreBuilder {
160
160
ObjectStoreKind :: Local => ObjectStoreImpl :: Local ( LocalFileSystem :: new ( ) ) ,
161
161
ObjectStoreKind :: InMemory => ObjectStoreImpl :: InMemory ( InMemory :: new ( ) ) ,
162
162
ObjectStoreKind :: Azure => {
163
- let maybe_store = MicrosoftAzureBuilder :: new ( )
163
+ let store = MicrosoftAzureBuilder :: new ( )
164
164
. with_url ( url. clone ( ) )
165
165
. try_with_options ( & self . options ) ?
166
166
. with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
167
167
. 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)
180
178
}
181
179
ObjectStoreKind :: S3 => {
182
- let maybe_store = AmazonS3Builder :: new ( )
180
+ let store = AmazonS3Builder :: new ( )
183
181
. with_url ( url. clone ( ) )
184
182
. try_with_options ( & self . options ) ?
185
183
. with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
186
184
. 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)
199
195
}
200
196
ObjectStoreKind :: Google => {
201
- let maybe_store = GoogleCloudStorageBuilder :: new ( )
197
+ let store = GoogleCloudStorageBuilder :: new ( )
202
198
. with_url ( url. clone ( ) )
203
199
. try_with_options ( & self . options ) ?
204
200
. with_client_options ( self . client_options . clone ( ) . unwrap_or_default ( ) )
205
201
. 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)
218
212
}
219
213
} ;
220
214
0 commit comments