Skip to content

Commit

Permalink
Merge pull request #97 from sminez/ninep-sansio
Browse files Browse the repository at this point in the history
A sans-io API for ninep
  • Loading branch information
sminez authored Mar 5, 2025
2 parents 87f3b1d + 4682a82 commit ecf526e
Show file tree
Hide file tree
Showing 29 changed files with 3,747 additions and 1,834 deletions.
332 changes: 235 additions & 97 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ harness = false

[dependencies]
ad_event = { version = "0.3", path = "crates/ad_event" }
ninep = { version = "0.3", path = "crates/ninep" }
ninep = { version = "0.4", path = "crates/ninep" }
libc = "0.2.159"
lsp-types = "0.97.0"
serde = "1.0.215"
Expand Down
4 changes: 2 additions & 2 deletions crates/ad_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ad_client"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["sminez <[email protected]>"]
license = "MIT"
Expand All @@ -19,4 +19,4 @@ categories = [ "development-tools", "text-editors", "command-line-utilities" ]

[dependencies]
ad_event = { version = "0.3", path = "../ad_event" }
ninep = { version = "0.3", path = "../ninep" }
ninep = { version = "0.4", path = "../ninep" }
2 changes: 1 addition & 1 deletion crates/ad_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
rustdoc::all,
clippy::undocumented_unsafe_blocks
)]
use ninep::client::{ReadLineIter, UnixClient};
use ninep::sync::client::{ReadLineIter, UnixClient};
use std::{io, io::Write, os::unix::net::UnixStream};

mod event;
Expand Down
9 changes: 8 additions & 1 deletion crates/ninep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ninep"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
authors = ["sminez <[email protected]>"]
license = "MIT"
Expand All @@ -13,8 +13,15 @@ include = [
"README.md"
]

[features]
default = ["tokio"]
tokio = ["dep:tokio"]

[dependencies]
bitflags = "2.6"
tokio = { version = "1.43.0", features = ["macros", "net", "io-util", "rt", "sync"], optional = true }
simple_coro = "0.1"

[dev-dependencies]
simple_test_case = "1"
tokio = { version = "1.43.0", features = ["macros", "net", "io-util", "rt", "sync", "time", "rt-multi-thread", "net", "io-util"] }
2 changes: 1 addition & 1 deletion crates/ninep/examples/acme_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! A simple demo of the 9p client interface
use ninep::client::UnixClient;
use ninep::sync::client::UnixClient;
use std::io;

fn main() -> io::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/ninep/examples/ad_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! A simple demo of the 9p client interface
use ninep::client::UnixClient;
use ninep::sync::client::UnixClient;
use std::io;

fn main() -> io::Result<()> {
Expand Down
33 changes: 33 additions & 0 deletions crates/ninep/examples/async_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! A simple demo of the 9p client interface
use ninep::{fs::FileType, tokio::client::UnixClient};
use std::io;

#[tokio::main]
async fn main() -> io::Result<()> {
let mut client = UnixClient::new_unix("ninep-server", "").await?;
tree(&mut client, "", 0).await?;

let mut stream = client.stream_lines("blocking").await?;
while let Some(line) = stream.next().await {
println!("{line}");
}

Ok(())
}

async fn tree(client: &mut UnixClient, path: &str, depth: usize) -> io::Result<()> {
for stat in client.read_dir(path).await? {
let name = stat.fm.name;
println!("{:indent$}{name}", "", indent = depth * 2);
if stat.fm.ty == FileType::Directory {
let child = if path.is_empty() {
name
} else {
format!("{path}/{name}")
};
Box::pin(tree(client, &child, depth + 1)).await?;
}
}

Ok(())
}
Loading

0 comments on commit ecf526e

Please sign in to comment.