pub trait Configurator:
Serialize
+ DeserializeOwned
+ Debug
+ 'static {
type Builder: Builder;
// Required method
fn into_builder(self) -> Self::Builder;
// Provided method
fn from_iter(
iter: impl IntoIterator<Item = (String, String)>,
) -> Result<Self> { ... }
}
Expand description
Configurator is used to configure the underlying service.
This trait allows the developer to define a configuration struct that can:
- deserialize from an iterator like hashmap or vector.
- convert into a service builder and finally build the underlying services.
Usually, users don’t need to use or import this trait directly, they can use Operator
API instead.
For example:
use std::collections::HashMap;
use opendal::services::MemoryConfig;
use opendal::Operator;
async fn test() -> Result<()> {
let mut cfg = MemoryConfig::default();
cfg.root = Some("/".to_string());
// Build an `Operator` to start operating the storage.
let op: Operator = Operator::from_config(cfg)?.finish();
Ok(())
}
Some service builder might contain in memory options like http_client
. Users can call
into_builder
to convert the configuration into a builder instead.
use std::collections::HashMap;
use opendal::raw::HttpClient;
use opendal::services::S3Config;
use opendal::Configurator;
use opendal::Operator;
async fn test() -> Result<()> {
let mut cfg = S3Config::default();
cfg.root = Some("/".to_string());
cfg.bucket = "test".to_string();
let builder = cfg.into_builder();
let builder = builder.http_client(HttpClient::new()?);
// Build an `Operator` to start operating the storage.
let op: Operator = Operator::new(builder)?.finish();
Ok(())
}
Required Associated Types§
Required Methods§
Sourcefn into_builder(self) -> Self::Builder
fn into_builder(self) -> Self::Builder
Convert this configuration into a service builder.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.