Skip to content

Commit

Permalink
Fix doctests, rename Config to StorageConfig in remi-fs
Browse files Browse the repository at this point in the history
  • Loading branch information
auguwu committed Oct 21, 2024
1 parent 0799fd6 commit 47e4136
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 8 additions & 4 deletions crates/fs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@

use std::path::{Path, PathBuf};

/// Type alias for [`StorageConfig`].
#[deprecated(since = "0.9.0", note = "Use the `StorageConfig` struct instead")]
pub type Config = StorageConfig;

/// Represents the main configuration of using the `StorageService` implementation of remi-fs.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Config {
pub struct StorageConfig {
/// [`PathBuf`] to the directory where `remi-fs` can locate files from with the `./` prefix.
pub directory: PathBuf,
}

impl Config {
impl StorageConfig {
/// Creates a new [`Config`] instance.
pub fn new<P: AsRef<Path>>(path: P) -> Config {
Config {
pub fn new<P: AsRef<Path>>(path: P) -> StorageConfig {
StorageConfig {
directory: path.as_ref().into(),
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/fs/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::{default_resolver, Config, ContentTypeResolver};
use crate::{default_resolver, ContentTypeResolver, StorageConfig};
use remi::{async_trait, Blob, Bytes, Directory, File, ListBlobsRequest, StorageService as _, UploadRequest};
use std::{
borrow::Cow,
Expand All @@ -38,17 +38,17 @@ use tracing::instrument;
#[derive(Clone)]
pub struct StorageService {
resolver: Arc<dyn ContentTypeResolver>,
config: Config,
config: StorageConfig,
}

impl StorageService {
/// Creates a new [`StorageService`] instance.
pub fn new<P: AsRef<Path>>(path: P) -> StorageService {
Self::with_config(Config::new(path))
Self::with_config(StorageConfig::new(path))
}

/// Creates a new [`StorageService`] instance with a provided configuration object.
pub fn with_config(config: Config) -> StorageService {
pub fn with_config(config: StorageConfig) -> StorageService {
StorageService {
resolver: Arc::new(default_resolver),
config,
Expand Down
6 changes: 2 additions & 4 deletions crates/gridfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ use remi::{StorageService as _, UploadRequest};
#[tokio::main]
async fn main() {
let storage = StorageService::new(StorageConfig {
// You can customise the MongoDB client here
client_options: mongodb::ClientOptions::builder().servers(vec!["mongodb://localhost:27017"]).build();
let storage = StorageService::from_conn_string("mongodb://localhost:27017", StorageConfig {
bucket: "my-bucket".into(),
..Default::default()
});
}).await.unwrap();
// Initialize the container. This will:
//
Expand Down

0 comments on commit 47e4136

Please sign in to comment.