1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use std::path;
use crate::channel::Channel;
use crate::fuse_handlers::FuseHandlers;
use crate::fuse_server::{self, FuseServer};
use crate::server;
#[cfg_attr(doc, doc(cfg(feature = "std")))]
pub trait FuseMount {
type Channel: fuse_server::FuseServerChannel;
fn fuse_mount(
self,
mount_target: &path::Path,
) -> Result<Self::Channel, <Self::Channel as Channel>::Error>;
}
#[cfg_attr(doc, doc(cfg(feature = "std")))]
pub struct FuseServerBuilder<Mount, Handlers, Hooks> {
mount_target: path::PathBuf,
mount: Mount,
handlers: Handlers,
hooks: Option<Hooks>,
}
impl<Handlers> FuseServerBuilder<(), Handlers, server::NoopServerHooks> {
pub fn new(
mount_target: impl AsRef<path::Path>,
handlers: Handlers,
) -> FuseServerBuilder<(), Handlers, server::NoopServerHooks> {
FuseServerBuilder {
mount_target: path::PathBuf::from(mount_target.as_ref()),
mount: (),
handlers,
hooks: None,
}
}
}
impl<Mount, Handlers, Hooks> FuseServerBuilder<Mount, Handlers, Hooks> {
pub fn set_hooks<H>(
self,
hooks: H,
) -> FuseServerBuilder<Mount, Handlers, H> {
FuseServerBuilder {
mount_target: self.mount_target,
mount: self.mount,
handlers: self.handlers,
hooks: Some(hooks),
}
}
pub fn set_mount<M>(
self,
mount: M,
) -> FuseServerBuilder<M, Handlers, Hooks> {
FuseServerBuilder {
mount_target: self.mount_target,
mount,
handlers: self.handlers,
hooks: self.hooks,
}
}
}
impl<M, Handlers, Hooks> FuseServerBuilder<M, Handlers, Hooks>
where
M: FuseMount,
Handlers: FuseHandlers,
Hooks: server::ServerHooks,
{
pub fn build(
self,
) -> Result<
FuseServer<M::Channel, Handlers, Hooks>,
<<M as FuseMount>::Channel as Channel>::Error,
> {
let channel = self.mount.fuse_mount(&self.mount_target)?;
let mut builder =
fuse_server::FuseServerBuilder::new(channel, self.handlers);
if let Some(hooks) = self.hooks {
builder = builder.set_hooks(hooks);
}
builder.build()
}
}