Skip to main content

ServiceFsDir

Struct 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>

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.

§Panics

Panics if any node has already been added with the discoverable protocol name.

Source

pub fn add_service_at( &mut self, name: impl TryInto<Name, Error: Debug>, service: impl Into<ServiceObjTy>, ) -> &mut Self

Adds a service to the directory with the given name.

§Panics

Panics if name is not a valid fuchsia.io [Name], or if any node has already been added with the given name.

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.

§Panics

Panics if any node has already been added with the discoverable protocol name.

Source

pub fn add_fidl_service_at<F, RS>( &mut self, name: impl TryInto<Name, Error: Debug>, 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 with the given name.

See add_fidl_service for details.

§Panics

Panics if name is not a valid fuchsia.io [Name], or if any node has already been added with the given name.

Source

pub fn add_fidl_service_instance<F, SR>( &mut self, instance: impl TryInto<Name, Error: Debug>, 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.

§Example

For the following FIDL definition,

library lib.foo;

service Bar {
  ...
}

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

§Panics

Panics if instance is not a valid fuchsia.io [Name], or if an entry has already been added that conflicts with the service or instance directory structure.

Source

pub fn add_fidl_service_instance_at<F, SR>( &mut self, name: impl TryInto<Name, Error: Debug>, instance: impl TryInto<Name, Error: Debug>, 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 with the given name.

The FIDL service will be hosted at [name]/[instance]/.

§Panics

Panics if name or instance is not a valid fuchsia.io [Name], or if an entry has already been added that conflicts with the service or instance directory structure.

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.

The FIDL service will be hosted at the name provided by the [Discoverable] annotation in the FIDL source.

§Panics

Panics if any node has already been added with the discoverable protocol name.

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.

The FIDL service will be hosted at the name provided by the [Discoverable] annotation in the FIDL source.

§Panics

Panics if any node has already been added with the discoverable protocol name.

Source

pub fn add_vmo_file_at( &mut self, name: impl TryInto<Name, Error: Debug>, vmo: Vmo, ) -> &mut Self

Adds a VMO file to the directory with the given name.

The vmo should have content size set as required.

§Panics

Panics if name is not a valid fuchsia.io [Name], or if any node has already been added with the given name.

Source

pub fn add_entry_at( &mut self, name: impl TryInto<Name, Error: Debug>, entry: Arc<dyn DirectoryEntry>, ) -> &mut Self

Adds an entry to the directory with the given name.

§Panics

Panics if name is not a valid fuchsia.io [Name], or if any node has already been added with the given name.

Source

pub fn dir( &mut self, name: impl TryInto<Name, Error: Debug>, ) -> ServiceFsDir<'_, ServiceObjTy>

Returns a reference to the subdirectory with the given name, creating one if none exists.

§Panics

Panics if name is not a valid fuchsia.io [Name], or if an entry has already been added with the given name and it is not a directory.

Source

pub fn add_remote( &mut self, name: impl TryInto<Name, Error: Debug>, proxy: DirectoryProxy, ) -> &mut Self

Adds a new remote directory served over the given DirectoryProxy.

§Panics

Panics if name is not a valid fuchsia.io [Name], or if any node has already been added with the given name.

Source

pub fn add_fidl_next_protocol<P, H>( &mut self, create_handler: impl Fn(Server<P, Channel>) -> H + Send + Sync + Clone + 'static, ) -> &mut Self
where P: Discoverable + DispatchServerMessage<H, Channel>, H: Send + Sync + 'static,

Adds a FIDL protocol to the directory.

The FIDL protocol will be hosted at the name provided by the Discoverable annotation in the FIDL source.

§Panics

Panics if any node has already been added with the discoverable protocol name.

Source

pub fn add_fidl_next_service_instance<S, H>( &mut self, instance_name: impl TryInto<Name, Error: Debug>, handler: H, ) -> &mut Self
where S: DiscoverableService + DispatchServiceHandler<H, Channel> + 'static, H: Send + Sync + 'static,

Adds a FIDL service to the directory.

The FIDL service will be hosted at the name provided by the Discoverable annotation in the FIDL source under [instance_name].

§Panics

Panics if instance_name is not a valid fuchsia.io [Name], or if an entry has already been added that conflicts with the service or instance directory structure.

Source

pub fn add_fidl_next_service_instance_at<S, H>( &mut self, name: impl TryInto<Name, Error: Debug>, instance_name: impl TryInto<Name, Error: Debug>, handler: H, ) -> &mut Self
where S: DiscoverableService + DispatchServiceHandler<H, Channel> + 'static, H: Send + Sync + 'static,

Adds a FIDL service to the directory with a custom service name.

The FIDL service will be hosted at [name]/[instance_name]/.

§Panics

Panics if name or instance_name is not a valid fuchsia.io [Name], or if an entry has already been added that conflicts with the service or instance directory structure.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<'a, ServiceObjTy> UnsafeUnpin 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, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _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, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _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> InstanceFromServiceTransport<T> for T

§

fn from_service_transport(handle: T) -> T

Converts the given service transport handle of type T to [Self]
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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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
§

impl<E> RunsTransport<Mpsc> for E

§

impl<E> RunsTransport<Mpsc> for E
where E: RunsTransport<Mpsc>,

Source§

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

Source§

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>,

Source§

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