Skip to content

Commit 3d34dfc

Browse files
committed
AppBuilder: Extract storage_from_config() fn
1 parent 1a17ba0 commit 3d34dfc

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/app.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::Arc;
77
use crate::email::Emails;
88
use crate::metrics::{InstanceMetrics, ServiceMetrics};
99
use crate::rate_limiter::RateLimiter;
10-
use crate::storage::Storage;
10+
use crate::storage::{Storage, StorageConfig};
1111
use axum::extract::{FromRef, FromRequestParts, State};
1212
use bon::Builder;
1313
use crates_io_github::GitHubClient;
@@ -142,6 +142,16 @@ impl<S: app_builder::State> AppBuilder<S> {
142142
self.primary_database(primary_database)
143143
.maybe_replica_database(replica_database)
144144
}
145+
146+
pub fn storage_from_config(
147+
self,
148+
config: &StorageConfig,
149+
) -> AppBuilder<app_builder::SetStorage<S>>
150+
where
151+
S::Storage: app_builder::IsUnset,
152+
{
153+
self.storage(Arc::new(Storage::from_config(config)))
154+
}
145155
}
146156

147157
impl App {
@@ -158,7 +168,7 @@ impl App {
158168
.github(github)
159169
.github_oauth_from_config(&config)
160170
.emails(emails)
161-
.storage(Arc::new(Storage::from_config(&config.storage)))
171+
.storage_from_config(&config.storage)
162172
.rate_limiter(RateLimiter::new(config.rate_limiter.clone()))
163173
.config(Arc::new(config))
164174
.build()

0 commit comments

Comments
 (0)