You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/05/27 08:09:52 UTC

[incubator-opendal] branch main updated: docs: add service doc for fs (#2337)

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 274582e9 docs: add service doc for fs (#2337)
274582e9 is described below

commit 274582e9781088aa9e89d8cd8fff53180962b609
Author: Suyan <su...@gmail.com>
AuthorDate: Sat May 27 16:09:47 2023 +0800

    docs: add service doc for fs (#2337)
    
    * docs: add service doc for fs
    
    Signed-off-by: suyanhanx <su...@gmail.com>
    
    * format
    
    Signed-off-by: suyanhanx <su...@gmail.com>
    
    * fix scheme
    
    Signed-off-by: suyanhanx <su...@gmail.com>
    
    ---------
    
    Signed-off-by: suyanhanx <su...@gmail.com>
---
 core/src/services/fs/backend.rs | 50 +-------------------------------
 core/src/services/fs/docs.md    | 50 ++++++++++++++++++++++++++++++++
 website/docs/services/azdfs.mdx |  6 +++-
 website/docs/services/fs.mdx    | 63 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 119 insertions(+), 50 deletions(-)

diff --git a/core/src/services/fs/backend.rs b/core/src/services/fs/backend.rs
index 824107e1..98cb46bc 100644
--- a/core/src/services/fs/backend.rs
+++ b/core/src/services/fs/backend.rs
@@ -36,55 +36,7 @@ use crate::*;
 
 /// POSIX file system support.
 ///
-/// # Capabilities
-///
-/// This service can be used to:
-///
-/// - [x] stat
-/// - [x] read
-/// - [x] write
-/// - [x] append
-/// - [x] create_dir
-/// - [x] delete
-/// - [x] copy
-/// - [x] rename
-/// - [x] list
-/// - [ ] ~~scan~~
-/// - [ ] ~~presign~~
-/// - [x] blocking
-///
-/// # Configuration
-///
-/// - `root`: Set the work dir for backend.
-///
-/// Refer to [`FsBuilder`]'s public API docs for more information.
-///
-/// # Example
-///
-/// ## Via Builder
-///
-/// ```
-/// use std::sync::Arc;
-///
-/// use anyhow::Result;
-/// use opendal::services::Fs;
-/// use opendal::Operator;
-///
-/// #[tokio::main]
-/// async fn main() -> Result<()> {
-///     // Create fs backend builder.
-///     let mut builder = Fs::default();
-///     // Set the root for fs, 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(())
-/// }
-/// ```
+#[doc = include_str!("docs.md")]
 #[derive(Default, Debug)]
 pub struct FsBuilder {
     root: Option<PathBuf>,
diff --git a/core/src/services/fs/docs.md b/core/src/services/fs/docs.md
new file mode 100644
index 00000000..f47d36be
--- /dev/null
+++ b/core/src/services/fs/docs.md
@@ -0,0 +1,50 @@
+# Capabilities
+
+This service can be used to:
+
+- [x] stat
+- [x] read
+- [x] write
+- [x] append
+- [x] create_dir
+- [x] delete
+- [x] copy
+- [x] rename
+- [x] list
+- [ ] ~~scan~~
+- [ ] ~~presign~~
+- [x] blocking
+
+# Configuration
+
+- `root`: Set the work dir for backend.
+
+Refer to public API docs for more information.
+
+# Example
+
+### Via Builder
+
+
+```rust
+use std::sync::Arc;
+
+use anyhow::Result;
+use opendal::services::Fs;
+use opendal::Operator;
+
+#[tokio::main]
+async fn main() -> Result<()> {
+    // Create fs backend builder.
+    let mut builder = Fs::default();
+    // Set the root for fs, 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(())
+}
+```
diff --git a/website/docs/services/azdfs.mdx b/website/docs/services/azdfs.mdx
index 07ea4dab..cb5b1466 100644
--- a/website/docs/services/azdfs.mdx
+++ b/website/docs/services/azdfs.mdx
@@ -19,10 +19,11 @@ import TabItem from '@theme/TabItem';
 
 ```rust
 use std::sync::Arc;
+
 use anyhow::Result;
-use opendal::services::Azdfs;
 use opendal::Scheme;
 use opendal::Operator;
+
 #[tokio::main]
 async fn main() -> Result<()> {
     let mut map = HashMap::new();
@@ -31,6 +32,7 @@ async fn main() -> Result<()> {
     map.insert("endpoint".to_string(), "https://accountname.dfs.core.windows.net".to_string());
     map.insert("account_name".to_string(), "account_name".to_string());
     map.insert("account_key".to_string(), "account_key".to_string());
+
     let op: Operator = Operator::via_map(Scheme::Azdfs, map)?;
     Ok(())
 }
@@ -41,6 +43,7 @@ async fn main() -> Result<()> {
 
 ```javascript
 import { Operator } from "opendal";
+
 async function main() {
   const op = new Operator("azdfs", {
     root: "/path/to/dir",
@@ -57,6 +60,7 @@ async function main() {
 
 ```python
 import opendal
+
 op = opendal.Operator("azdfs",
     root="/path/to/dir",
     filesystem="test",
diff --git a/website/docs/services/fs.mdx b/website/docs/services/fs.mdx
new file mode 100644
index 00000000..851addb5
--- /dev/null
+++ b/website/docs/services/fs.mdx
@@ -0,0 +1,63 @@
+---
+title: Fs
+---
+
+POSIX file system support.
+
+import Docs from '../../../core/src/services/fs/docs.md'
+
+<Docs components={props.components} />
+
+### Via Config
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+<Tabs>
+  <TabItem value="rust" label="Rust" default>
+
+```rust
+use std::sync::Arc;
+
+use anyhow::Result;
+use opendal::Scheme;
+use opendal::Operator;
+
+#[tokio::main]
+async fn main() -> Result<()> {
+  let mut map = HashMap::new();
+  map.insert("root".to_string(), "/path/to/dir".to_string());
+
+  let op: Operator = Operator::via_map(Scheme::Fs, map)?;
+  Ok(())
+}
+```
+
+  </TabItem>
+  <TabItem value="node.js" label="Node.js">
+
+```javascript
+import { Operator } from "opendal";
+
+async function main() {
+  const op = new Operator("fs", {
+    root: "/path/to/dir",
+  });
+}
+```
+
+  </TabItem>
+  <TabItem value="python" label="Python">
+
+```python
+import opendal
+
+op = opendal.Operator("fs",
+    root="/path/to/dir",
+)
+```
+
+  </TabItem>
+</Tabs>
+
+