Skip to content

Commit abfec64

Browse files
pietroalbiniJoshua Nelson
authored and
Joshua Nelson
committed
address review comments
1 parent 05ea13b commit abfec64

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::storage::StorageBackendKind;
1+
use crate::storage::StorageKind;
22
use failure::{bail, format_err, Error, Fail, ResultExt};
33
use rusoto_core::Region;
44
use std::env::VarError;
@@ -19,7 +19,7 @@ pub struct Config {
1919
pub(crate) min_pool_idle: u32,
2020

2121
// Storage params
22-
pub(crate) storage_backend: StorageBackendKind,
22+
pub(crate) storage_backend: StorageKind,
2323

2424
// S3 params
2525
pub(crate) s3_bucket: String,
@@ -55,7 +55,7 @@ impl Config {
5555
max_pool_size: env("DOCSRS_MAX_POOL_SIZE", 90)?,
5656
min_pool_idle: env("DOCSRS_MIN_POOL_IDLE", 10)?,
5757

58-
storage_backend: env("DOCSRS_STORAGE_BACKEND", StorageBackendKind::Database)?,
58+
storage_backend: env("DOCSRS_STORAGE_BACKEND", StorageKind::Database)?,
5959

6060
s3_bucket: env("DOCSRS_S3_BUCKET", "rust-docs-rs".to_string())?,
6161
s3_region: env("S3_REGION", Region::UsWest1)?,

src/storage/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ pub fn get_file_list<P: AsRef<Path>>(path: P) -> Result<Vec<PathBuf>, Error> {
7272
pub(crate) struct InvalidStorageBackendError;
7373

7474
#[derive(Debug)]
75-
pub(crate) enum StorageBackendKind {
75+
pub(crate) enum StorageKind {
7676
Database,
7777
S3,
7878
}
7979

80-
impl std::str::FromStr for StorageBackendKind {
80+
impl std::str::FromStr for StorageKind {
8181
type Err = InvalidStorageBackendError;
8282

8383
fn from_str(input: &str) -> Result<Self, Self::Err> {
8484
match input {
85-
"database" => Ok(StorageBackendKind::Database),
86-
"s3" => Ok(StorageBackendKind::S3),
85+
"database" => Ok(StorageKind::Database),
86+
"s3" => Ok(StorageKind::S3),
8787
_ => Err(InvalidStorageBackendError),
8888
}
8989
}
@@ -102,12 +102,10 @@ impl Storage {
102102
pub fn new(pool: Pool, metrics: Arc<Metrics>, config: &Config) -> Result<Self, Error> {
103103
Ok(Storage {
104104
backend: match config.storage_backend {
105-
StorageBackendKind::Database => {
105+
StorageKind::Database => {
106106
StorageBackend::Database(DatabaseBackend::new(pool, metrics))
107107
}
108-
StorageBackendKind::S3 => {
109-
StorageBackend::S3(Box::new(S3Backend::new(metrics, config)?))
110-
}
108+
StorageKind::S3 => StorageBackend::S3(Box::new(S3Backend::new(metrics, config)?)),
111109
},
112110
})
113111
}
@@ -579,7 +577,7 @@ mod backend_tests {
579577
$(
580578
mod $backend {
581579
use crate::test::TestEnvironment;
582-
use crate::storage::{Storage, StorageBackendKind};
580+
use crate::storage::{Storage, StorageKind};
583581
use std::sync::Arc;
584582

585583
fn get_storage(env: &TestEnvironment) -> Arc<Storage> {
@@ -618,8 +616,8 @@ mod backend_tests {
618616

619617
backend_tests! {
620618
backends {
621-
s3 => StorageBackendKind::S3,
622-
database => StorageBackendKind::Database,
619+
s3 => StorageKind::S3,
620+
database => StorageKind::Database,
623621
}
624622

625623
tests {

src/storage/s3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl S3Backend {
3939
name: config.s3_region.name().to_string(),
4040
endpoint: endpoint.to_string(),
4141
})
42-
.unwrap_or(config.s3_region.clone()),
42+
.unwrap_or_else(|| config.s3_region.clone()),
4343
);
4444

4545
#[cfg(test)]

src/test/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod fakes;
22

33
use crate::db::{Pool, PoolClient};
4-
use crate::storage::{Storage, StorageBackendKind};
4+
use crate::storage::{Storage, StorageKind};
55
use crate::web::Server;
66
use crate::{BuildQueue, Config, Context, Metrics};
77
use failure::Error;
@@ -139,7 +139,7 @@ impl TestEnvironment {
139139
config.min_pool_idle = 0;
140140

141141
// Use the database for storage, as it's faster than S3.
142-
config.storage_backend = StorageBackendKind::Database;
142+
config.storage_backend = StorageKind::Database;
143143

144144
// Use a temporary S3 bucket.
145145
config.s3_bucket = format!("docsrs-test-bucket-{}", rand::random::<u64>());

0 commit comments

Comments
 (0)