-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(services): init monoiofs (#4855)
* feat(services): init monoiofs * refactor(services/monoiofs): derive Debug instead of manual impl It is unlikely to introduce credentials or non-primitive fields in MonoiofsConfig, so default Debug implementation should be fine.
- Loading branch information
Showing
8 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::fmt::Debug; | ||
|
||
use serde::Deserialize; | ||
|
||
use crate::raw::*; | ||
use crate::*; | ||
|
||
/// Config for monoiofs services support. | ||
#[derive(Default, Deserialize, Debug)] | ||
#[serde(default)] | ||
#[non_exhaustive] | ||
pub struct MonoiofsConfig { | ||
/// The Root of this backend. | ||
/// | ||
/// All operations will happen under this root. | ||
/// | ||
/// Default to `/` if not set. | ||
pub root: Option<String>, | ||
} | ||
|
||
/// File system support via [`monoio`]. | ||
#[doc = include_str!("docs.md")] | ||
#[derive(Default, Debug)] | ||
pub struct MonoiofsBuilder { | ||
config: MonoiofsConfig, | ||
} | ||
|
||
impl MonoiofsBuilder { | ||
/// Set root of this backend. | ||
/// | ||
/// All operations will happen under this root. | ||
pub fn root(&mut self, root: &str) -> &mut Self { | ||
self.config.root = if root.is_empty() { | ||
None | ||
} else { | ||
Some(root.to_string()) | ||
}; | ||
|
||
self | ||
} | ||
} | ||
|
||
impl Builder for MonoiofsBuilder { | ||
const SCHEME: Scheme = Scheme::Monoiofs; | ||
|
||
type Accessor = MonoiofsBackend; | ||
|
||
fn from_map(map: std::collections::HashMap<String, String>) -> Self { | ||
let config = MonoiofsConfig::deserialize(ConfigDeserializer::new(map)) | ||
.expect("config deserialize must succeed"); | ||
|
||
MonoiofsBuilder { config } | ||
} | ||
|
||
fn build(&mut self) -> Result<Self::Accessor> { | ||
todo!() | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct MonoiofsBackend {} | ||
|
||
impl Access for MonoiofsBackend { | ||
type Reader = (); | ||
type Writer = (); | ||
type Lister = (); | ||
type BlockingReader = (); | ||
type BlockingWriter = (); | ||
type BlockingLister = (); | ||
|
||
fn info(&self) -> AccessorInfo { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
## Capabilities | ||
|
||
This service can be used to: | ||
|
||
- [ ] stat | ||
- [ ] read | ||
- [ ] write | ||
- [ ] append | ||
- [ ] create_dir | ||
- [ ] delete | ||
- [ ] copy | ||
- [ ] rename | ||
- [ ] list | ||
- [ ] ~~presign~~ | ||
- [ ] blocking | ||
|
||
## Configuration | ||
|
||
- `root`: Set the work dir for backend. | ||
|
||
You can refer to [`MonoiofsBuilder`]'s docs for more information | ||
|
||
## Example | ||
|
||
### Via Builder | ||
|
||
```rust,no_run | ||
use anyhow::Result; | ||
use opendal::services::Monoiofs; | ||
use opendal::Operator; | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// Create monoiofs backend builder. | ||
let mut builder = Monoiofs::default(); | ||
// Set the root for monoiofs, all operations will happen under this root. | ||
// | ||
// NOTE: the root must be absolute path. | ||
builder.root("/tmp"); | ||
// `Accessor` provides the low level APIs, we will use `Operator` normally. | ||
let op: Operator = Operator::new(builder)?.finish(); | ||
Ok(()) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
mod backend; | ||
pub use backend::MonoiofsBuilder as Monoiofs; | ||
pub use backend::MonoiofsConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters