Struct fuchsia_component::server::ServiceFsDir
source · pub struct ServiceFsDir<'a, ServiceObjTy: ServiceObjTrait> { /* private fields */ }
Expand description
A directory within a ServiceFs
.
Services and subdirectories can be added to it.
Implementations§
source§impl<ServiceObjTy: ServiceObjTrait> ServiceFsDir<'_, ServiceObjTy>
impl<ServiceObjTy: ServiceObjTrait> ServiceFsDir<'_, ServiceObjTy>
sourcepub fn add_service_connector<F, P>(&mut self, service: F) -> &mut Selfwhere
F: FnMut(ServerEnd<P>) -> ServiceObjTy::Output,
P: DiscoverableProtocolMarker,
FidlServiceServerConnector<F, P, ServiceObjTy::Output>: Into<ServiceObjTy>,
pub fn add_service_connector<F, P>(&mut self, service: F) -> &mut Selfwhere
F: FnMut(ServerEnd<P>) -> ServiceObjTy::Output,
P: DiscoverableProtocolMarker,
FidlServiceServerConnector<F, P, ServiceObjTy::Output>: Into<ServiceObjTy>,
Adds a service connector to the directory.
let mut fs = ServiceFs::new_local();
fs
.add_service_connector(|server_end: ServerEnd<EchoMarker>| {
connect_channel_to_protocol::<EchoMarker>(
server_end.into_channel(),
)
})
.add_service_connector(|server_end: ServerEnd<CustomMarker>| {
connect_channel_to_protocol::<CustomMarker>(
server_end.into_channel(),
)
})
.take_and_serve_directory_handle()?;
The FIDL service will be hosted at the name provided by the
[Discoverable]
annotation in the FIDL source.
sourcepub fn add_service_at(
&mut self,
path: impl Into<String>,
service: impl Into<ServiceObjTy>,
) -> &mut Self
pub fn add_service_at( &mut self, path: impl Into<String>, service: impl Into<ServiceObjTy>, ) -> &mut Self
Adds a service to the directory at the given path.
The path must be a single component containing no /
characters.
Panics if any node has already been added at the given path.
sourcepub fn add_fidl_service<F, RS>(&mut self, service: F) -> &mut Selfwhere
F: FnMut(RS) -> ServiceObjTy::Output,
RS: RequestStream,
RS::Protocol: DiscoverableProtocolMarker,
FidlService<F, RS, ServiceObjTy::Output>: Into<ServiceObjTy>,
pub fn add_fidl_service<F, RS>(&mut self, service: F) -> &mut Selfwhere
F: FnMut(RS) -> ServiceObjTy::Output,
RS: RequestStream,
RS::Protocol: DiscoverableProtocolMarker,
FidlService<F, RS, ServiceObjTy::Output>: Into<ServiceObjTy>,
Adds a FIDL service to the directory.
service
is a closure that accepts a RequestStream
.
Each service being served must return an instance of the same type
(ServiceObjTy::Output
). This is necessary in order to multiplex
multiple services over the same dispatcher code. The typical way
to do this is to create an enum
with variants for each service
you want to serve.
enum MyServices {
EchoServer(EchoRequestStream),
CustomServer(CustomRequestStream),
// ...
}
The constructor for a variant of the MyServices
enum can be passed
as the service
parameter.
let mut fs = ServiceFs::new_local();
fs
.add_fidl_service(MyServices::EchoServer)
.add_fidl_service(MyServices::CustomServer)
.take_and_serve_directory_handle()?;
ServiceFs
can now be treated as a Stream
of type MyServices
.
const MAX_CONCURRENT: usize = 10_000;
fs.for_each_concurrent(MAX_CONCURRENT, |request: MyServices| {
match request {
MyServices::EchoServer(request) => handle_echo(request),
MyServices::CustomServer(request) => handle_custom(request),
}
}).await;
The FIDL service will be hosted at the name provided by the
[Discoverable]
annotation in the FIDL source.
sourcepub fn add_fidl_service_at<F, RS>(
&mut self,
path: impl Into<String>,
service: F,
) -> &mut Selfwhere
F: FnMut(RS) -> ServiceObjTy::Output,
RS: RequestStream,
RS::Protocol: DiscoverableProtocolMarker,
FidlService<F, RS, ServiceObjTy::Output>: Into<ServiceObjTy>,
pub fn add_fidl_service_at<F, RS>(
&mut self,
path: impl Into<String>,
service: F,
) -> &mut Selfwhere
F: FnMut(RS) -> ServiceObjTy::Output,
RS: RequestStream,
RS::Protocol: DiscoverableProtocolMarker,
FidlService<F, RS, ServiceObjTy::Output>: Into<ServiceObjTy>,
Adds a FIDL service to the directory at the given path.
The path must be a single component containing no /
characters.
See add_fidl_service
for details.
sourcepub fn add_fidl_service_instance<F, SR>(
&mut self,
instance: impl Into<String>,
service: F,
) -> &mut Selfwhere
F: Fn(SR) -> ServiceObjTy::Output + Clone,
SR: ServiceRequest,
FidlServiceMember<F, SR, ServiceObjTy::Output>: Into<ServiceObjTy>,
pub fn add_fidl_service_instance<F, SR>(
&mut self,
instance: impl Into<String>,
service: F,
) -> &mut Selfwhere
F: Fn(SR) -> ServiceObjTy::Output + Clone,
SR: ServiceRequest,
FidlServiceMember<F, SR, ServiceObjTy::Output>: Into<ServiceObjTy>,
Adds a named instance of a FIDL service to the directory.
The FIDL service will be hosted at [SERVICE_NAME]/[instance]/
where SERVICE_NAME
is
constructed from the FIDL library path and the name of the FIDL service.
The instance
must be a single component containing no /
characters.
§Example
For the following FIDL definition,
library lib.foo;
service Bar {
...
}
The SERVICE_NAME
of FIDL Service Bar
would be lib.foo.Bar
.
sourcepub fn add_fidl_service_instance_at<F, SR>(
&mut self,
path: impl Into<String>,
instance: impl Into<String>,
service: F,
) -> &mut Selfwhere
F: Fn(SR) -> ServiceObjTy::Output + Clone,
SR: ServiceRequest,
FidlServiceMember<F, SR, ServiceObjTy::Output>: Into<ServiceObjTy>,
pub fn add_fidl_service_instance_at<F, SR>(
&mut self,
path: impl Into<String>,
instance: impl Into<String>,
service: F,
) -> &mut Selfwhere
F: Fn(SR) -> ServiceObjTy::Output + Clone,
SR: ServiceRequest,
FidlServiceMember<F, SR, ServiceObjTy::Output>: Into<ServiceObjTy>,
Adds a named instance of a FIDL service to the directory at the given path.
The FIDL service will be hosted at [path]/[instance]/
.
The path
and instance
must be single components containing no /
characters.
sourcepub fn add_proxy_service<P: DiscoverableProtocolMarker, O>(
&mut self,
) -> &mut Selfwhere
ServiceObjTy: From<Proxy<P, O>> + ServiceObjTrait<Output = O>,
pub fn add_proxy_service<P: DiscoverableProtocolMarker, O>(
&mut self,
) -> &mut Selfwhere
ServiceObjTy: From<Proxy<P, O>> + ServiceObjTrait<Output = O>,
Adds a service that proxies requests to the current environment.
sourcepub fn add_proxy_service_to<P: DiscoverableProtocolMarker, O>(
&mut self,
directory_request: Arc<ClientEnd<DirectoryMarker>>,
) -> &mut Selfwhere
ServiceObjTy: From<ProxyTo<P, O>> + ServiceObjTrait<Output = O>,
pub fn add_proxy_service_to<P: DiscoverableProtocolMarker, O>(
&mut self,
directory_request: Arc<ClientEnd<DirectoryMarker>>,
) -> &mut Selfwhere
ServiceObjTy: From<ProxyTo<P, O>> + ServiceObjTrait<Output = O>,
Adds a service that proxies requests to the given component.
sourcepub fn add_vmo_file_at(
&mut self,
path: impl Into<String>,
vmo: Vmo,
) -> &mut Self
pub fn add_vmo_file_at( &mut self, path: impl Into<String>, vmo: Vmo, ) -> &mut Self
Adds a VMO file to the directory at the given path.
The path must be a single component containing no /
characters. The vmo should have
content size set as required.
Panics if any node has already been added at the given path.
sourcepub fn add_entry_at(
&mut self,
path: impl Into<String>,
entry: Arc<dyn DirectoryEntry>,
) -> &mut Self
pub fn add_entry_at( &mut self, path: impl Into<String>, entry: Arc<dyn DirectoryEntry>, ) -> &mut Self
Adds an entry to the directory at the given path.
The path must be a single component.
The path must be a valid fuchsia.io
[Name
].
Panics if any node has already been added at the given path.
sourcepub fn dir(&mut self, path: impl Into<String>) -> ServiceFsDir<'_, ServiceObjTy>
pub fn dir(&mut self, path: impl Into<String>) -> ServiceFsDir<'_, ServiceObjTy>
Returns a reference to the subdirectory at the given path, creating one if none exists.
The path must be a single component.
The path must be a valid fuchsia.io
[Name
].
Panics if a service has already been added at the given path.
sourcepub fn add_remote(
&mut self,
name: impl Into<String>,
proxy: DirectoryProxy,
) -> &mut Self
pub fn add_remote( &mut self, name: impl Into<String>, proxy: DirectoryProxy, ) -> &mut Self
Adds a new remote directory served over the given DirectoryProxy.
The name must be a valid fuchsia.io
[Name
].