From d6f56f5cadcc36aaea6ce68c20d519fbc6283857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aurimas=20Bla=C5=BEulionis?= <0x60@pm.me> Date: Thu, 7 Dec 2023 18:39:20 +0200 Subject: [PATCH] Add mfio-netfs example --- mfio-netfs/examples/net_sample.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 mfio-netfs/examples/net_sample.rs diff --git a/mfio-netfs/examples/net_sample.rs b/mfio-netfs/examples/net_sample.rs new file mode 100644 index 0000000..fef3084 --- /dev/null +++ b/mfio-netfs/examples/net_sample.rs @@ -0,0 +1,24 @@ +use mfio::backend::*; +use mfio::error::Result; +use mfio::traits::*; +use mfio_netfs::NetworkFs; +use mfio_rt::*; + +fn main() -> Result<()> { + let rt = NativeRt::default(); + let rt = NetworkFs::with_fs("127.0.0.1:4446".parse().unwrap(), rt.into(), true)?; + + rt.block_on(async { + let file = rt + .open(Path::new("Cargo.toml"), OpenOptions::new().read(true)) + .await?; + + let mut buf = vec![]; + file.read_to_end(0, &mut buf).await?; + + let data = String::from_utf8_lossy(&buf); + println!("{data}"); + + Ok(()) + }) +}