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>

source

pub fn add_service_connector<F, P>(&mut self, service: F) -> &mut Self
where 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.

source

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.

source

pub fn add_fidl_service<F, RS>(&mut self, service: F) -> &mut Self
where 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.

source

pub fn add_fidl_service_at<F, RS>( &mut self, path: impl Into<String>, service: F ) -> &mut Self
where 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.

source

pub fn add_unified_service<F, SR>(&mut self, service: F) -> &mut Self
where F: Fn(SR) -> ServiceObjTy::Output + Clone, SR: ServiceRequest, FidlServiceMember<F, SR, ServiceObjTy::Output>: Into<ServiceObjTy>,

Adds a FIDL service to the directory as the default instance.

The name of the default instance is DEFAULT_SERVICE_INSTANCE.

The FIDL service will be hosted at [SERVICE_NAME]/[default]/ where SERVICE_NAME is constructed from the FIDL library path and the name of the FIDL service.

§Example

For the following FIDL definition,

library lib.foo;

service Bar {
  ...
}

The SERVICE_NAME of FIDL Service Bar would be lib.foo.Bar.

source

pub fn add_unified_service_at<F, SR>( &mut self, path: impl Into<String>, service: F ) -> &mut Self
where F: Fn(SR) -> ServiceObjTy::Output + Clone, SR: ServiceRequest, FidlServiceMember<F, SR, ServiceObjTy::Output>: Into<ServiceObjTy>,

Adds a FIDL service to the directory as the default instance at the given path.

The path must be a single component containing no / characters. The name of the default instance is DEFAULT_SERVICE_INSTANCE.

The FIDL service will be hosted at [path]/default/.

source

pub fn add_unified_service_instance<F, SR>( &mut self, instance: impl Into<String>, service: F ) -> &mut Self
where 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.

source

pub fn add_unified_service_instance_at<F, SR>( &mut self, path: impl Into<String>, instance: impl Into<String>, service: F ) -> &mut Self
where 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.

source

pub fn add_proxy_service<P: DiscoverableProtocolMarker, O>( &mut self ) -> &mut Self
where ServiceObjTy: From<Proxy<P, O>> + ServiceObjTrait<Output = O>,

Adds a service that proxies requests to the current environment.

source

pub fn add_proxy_service_to<P: DiscoverableProtocolMarker, O>( &mut self, directory_request: Arc<ClientEnd<DirectoryMarker>> ) -> &mut Self
where ServiceObjTy: From<ProxyTo<P, O>> + ServiceObjTrait<Output = O>,

Adds a service that proxies requests to the given component.

source

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.

source

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.

source

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.

source

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].

Auto Trait Implementations§

§

impl<'a, ServiceObjTy> Freeze for ServiceFsDir<'a, ServiceObjTy>

§

impl<'a, ServiceObjTy> !RefUnwindSafe for ServiceFsDir<'a, ServiceObjTy>

§

impl<'a, ServiceObjTy> Send for ServiceFsDir<'a, ServiceObjTy>
where ServiceObjTy: Send,

§

impl<'a, ServiceObjTy> !Sync for ServiceFsDir<'a, ServiceObjTy>

§

impl<'a, ServiceObjTy> Unpin for ServiceFsDir<'a, ServiceObjTy>

§

impl<'a, ServiceObjTy> !UnwindSafe for ServiceFsDir<'a, ServiceObjTy>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Encode<Ambiguous1> for T

source§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
source§

impl<T> Encode<Ambiguous2> for T

source§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more