Add open_dir
This commit is contained in:
parent
340a6a9ad3
commit
8ef50685a7
18
src/lib.rs
18
src/lib.rs
@ -14,6 +14,7 @@ const PROTO: u16 = 3;
|
|||||||
pub trait Server: Send + Sync {
|
pub trait Server: Send + Sync {
|
||||||
fn mount(&self, dev: &Path) -> Result<u64, ()>;
|
fn mount(&self, dev: &Path) -> Result<u64, ()>;
|
||||||
fn open(&self, path: &Path, mount_id: u64) -> Result<(Option<u64>, u64), ()>;
|
fn open(&self, path: &Path, mount_id: u64) -> Result<(Option<u64>, u64), ()>;
|
||||||
|
fn open_dir(&self, path: &Path, mount_id: u64) -> Result<(Option<u64>, u64), ()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@ -44,6 +45,19 @@ impl Client {
|
|||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn open_dir(self, path: &Path, mount_id: u64) -> Result<(Option<u64>, u64), ()> {
|
||||||
|
postcard::from_bytes(
|
||||||
|
&rpc::send_call(
|
||||||
|
self.0,
|
||||||
|
PROTO,
|
||||||
|
2,
|
||||||
|
&postcard::to_stdvec(&(path, mount_id)).unwrap(),
|
||||||
|
)
|
||||||
|
.get_return(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_server(server: Box<dyn Server>) {
|
pub fn register_server(server: Box<dyn Server>) {
|
||||||
@ -67,5 +81,9 @@ fn callback(call: IncomingCall) {
|
|||||||
let (path, mount_id) = postcard::from_bytes(call.args()).unwrap();
|
let (path, mount_id) = postcard::from_bytes(call.args()).unwrap();
|
||||||
let ret = postcard::to_stdvec(&server.open(path, mount_id)).unwrap();
|
let ret = postcard::to_stdvec(&server.open(path, mount_id)).unwrap();
|
||||||
call.send_return(&ret);
|
call.send_return(&ret);
|
||||||
|
} else if call.func == 2 {
|
||||||
|
let (path, mount_id) = postcard::from_bytes(call.args()).unwrap();
|
||||||
|
let ret = postcard::to_stdvec(&server.open_dir(path, mount_id)).unwrap();
|
||||||
|
call.send_return(&ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user