Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add from_iter and via_iter for operator #4921

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/oay/src/bin/oay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn s3() -> Result<()> {
let cfg: Config =
toml::from_str(&std::fs::read_to_string("oay.toml").context("failed to open oay.toml")?)?;
let scheme = Scheme::from_str(&cfg.backend.typ).context("unsupported scheme")?;
let op = Operator::via_map(scheme, cfg.backend.map.clone())?;
let op = Operator::via_iter(scheme, cfg.backend.map.clone())?;

let s3 = S3Service::new(Arc::new(cfg), op);

Expand Down
2 changes: 1 addition & 1 deletion bin/ofs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn execute(cfg: Config) -> Result<()> {
Ok(Scheme::Custom(_)) | Err(_) => Err(anyhow!("invalid scheme: {}", scheme_str)),
Ok(s) => Ok(s),
}?;
let backend = Operator::via_map(scheme, op_args)?;
let backend = Operator::via_iter(scheme, op_args)?;

let mut mount_options = MountOptions::default();
let mut gid = nix::unistd::getgid().into();
Expand Down
18 changes: 14 additions & 4 deletions bin/oli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 2 additions & 108 deletions bin/oli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,114 +162,8 @@ impl Config {
.get("type")
.ok_or_else(|| anyhow!("missing 'type' in profile"))?;
let scheme = Scheme::from_str(svc)?;
match scheme {
Scheme::Azblob => Ok((
Operator::from_map::<services::Azblob>(profile.clone())?.finish(),
path,
)),
Scheme::Azdls => Ok((
Operator::from_map::<services::Azdls>(profile.clone())?.finish(),
path,
)),
#[cfg(feature = "services-dashmap")]
Scheme::Dashmap => Ok((
Operator::from_map::<services::Dashmap>(profile.clone())?.finish(),
path,
)),
#[cfg(feature = "services-etcd")]
Scheme::Etcd => Ok((
Operator::from_map::<services::Etcd>(profile.clone())?.finish(),
path,
)),
Scheme::Gcs => Ok((
Operator::from_map::<services::Gcs>(profile.clone())?.finish(),
path,
)),
Scheme::Ghac => Ok((
Operator::from_map::<services::Ghac>(profile.clone())?.finish(),
path,
)),
#[cfg(feature = "services-hdfs")]
Scheme::Hdfs => Ok((
Operator::from_map::<services::Hdfs>(profile.clone())?.finish(),
path,
)),
Scheme::Http => Ok((
Operator::from_map::<services::Http>(profile.clone())?.finish(),
path,
)),
#[cfg(feature = "services-ftp")]
Scheme::Ftp => Ok((
Operator::from_map::<services::Ftp>(profile.clone())?.finish(),
path,
)),
#[cfg(feature = "services-ipfs")]
Scheme::Ipfs => Ok((
Operator::from_map::<services::Ipfs>(profile.clone())?.finish(),
path,
)),
Scheme::Ipmfs => Ok((
Operator::from_map::<services::Ipmfs>(profile.clone())?.finish(),
path,
)),
#[cfg(feature = "services-memcached")]
Scheme::Memcached => Ok((
Operator::from_map::<services::Memcached>(profile.clone())?.finish(),
path,
)),
// ignore the memory backend
#[cfg(feature = "services-mini-moka")]
Scheme::MiniMoka => Ok((
Operator::from_map::<services::MiniMoka>(profile.clone())?.finish(),
path,
)),
// ignore the memory backend
#[cfg(feature = "services-moka")]
Scheme::Moka => Ok((
Operator::from_map::<services::Moka>(profile.clone())?.finish(),
path,
)),
Scheme::Obs => Ok((
Operator::from_map::<services::Obs>(profile.clone())?.finish(),
path,
)),
Scheme::Oss => Ok((
Operator::from_map::<services::Oss>(profile.clone())?.finish(),
path,
)),
#[cfg(feature = "services-redis")]
Scheme::Redis => Ok((
Operator::from_map::<services::Redis>(profile.clone())?.finish(),
path,
)),
#[cfg(feature = "services-rocksdb")]
Scheme::Rocksdb => Ok((
Operator::from_map::<services::Rocksdb>(profile.clone())?.finish(),
path,
)),
Scheme::S3 => Ok((
Operator::from_map::<services::S3>(profile.clone())?.finish(),
path,
)),
#[cfg(feature = "services-sled")]
Scheme::Sled => Ok((
Operator::from_map::<services::Sled>(profile.clone())?.finish(),
path,
)),
Scheme::Webdav => Ok((
Operator::from_map::<services::Webdav>(profile.clone())?.finish(),
path,
)),
Scheme::Webhdfs => Ok((
Operator::from_map::<services::Webhdfs>(profile.clone())?.finish(),
path,
)),
_ => Err(anyhow!(
"unknown type '{}' in profile '{}'",
scheme,
profile_name
)),
}
let op = Operator::via_iter(scheme, profile.clone())?;
Ok((op, path))
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/raw/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn init_test_service() -> Result<Option<Operator>> {
cfg.insert("root".to_string(), root);
}

let op = Operator::via_map(scheme, cfg).expect("must succeed");
let op = Operator::via_iter(scheme, cfg).expect("must succeed");

#[cfg(feature = "layers-chaos")]
let op = { op.layer(layers::ChaosLayer::new(0.1)) };
Expand Down
5 changes: 2 additions & 3 deletions core/src/types/context/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,14 @@ impl ReadGenerator {

#[cfg(test)]
mod tests {
use std::collections::HashMap;

use bytes::Bytes;

use super::*;

#[tokio::test]
async fn test_next_reader() -> Result<()> {
let op = Operator::via_map(Scheme::Memory, HashMap::default())?;
let op = Operator::via_iter(Scheme::Memory, [])?;
op.write(
"test",
Buffer::from(vec![Bytes::from("Hello"), Bytes::from("World")]),
Expand All @@ -180,7 +179,7 @@ mod tests {

#[test]
fn test_next_blocking_reader() -> Result<()> {
let op = Operator::via_map(Scheme::Memory, HashMap::default())?;
let op = Operator::via_iter(Scheme::Memory, [])?;
op.blocking().write(
"test",
Buffer::from(vec![Bytes::from("Hello"), Bytes::from("World")]),
Expand Down
Loading
Loading