pub struct ScopedInstance { /* private fields */ }
Expand description
RAII object that keeps a component instance alive until it’s dropped, and provides convenience functions for using the instance. Components v2 only.
Implementations§
Source§impl ScopedInstance
impl ScopedInstance
Sourcepub async fn new(coll: String, url: String) -> Result<Self, Error>
pub async fn new(coll: String, url: String) -> Result<Self, Error>
Creates and binds to a new component just like new_with_name
, but uses an autogenerated
name for the instance.
Sourcepub async fn new_with_name(
child_name: String,
collection: String,
url: String,
) -> Result<Self, Error>
pub async fn new_with_name( child_name: String, collection: String, url: String, ) -> Result<Self, Error>
Creates and binds to a new component named child_name
in a collection coll
with url
,
and returning an object that represents the component’s lifetime and can be used to access
the component’s exposed directory. When the object is dropped, it will be asynchronously
stopped and destroyed. This is useful for tests that wish to create components that
should be torn down at the end of the test. Components v2 only.
Sourcepub async fn is_started(&self) -> Result<bool, Error>
pub async fn is_started(&self) -> Result<bool, Error>
Returns true if the component is currently running.
Sourcepub async fn start(&self) -> Result<ExecutionController, Error>
pub async fn start(&self) -> Result<ExecutionController, Error>
Starts the component. An error will be returned if the component is already running.
Sourcepub async fn start_with_args(
&self,
args: StartChildArgs,
) -> Result<ExecutionController, Error>
pub async fn start_with_args( &self, args: StartChildArgs, ) -> Result<ExecutionController, Error>
Starts the component with the provided start arguments. An error will be returned if the component is already running.
pub fn controller(&self) -> &ControllerProxy
Sourcepub fn connect_to_binder(&self) -> Result<BinderProxy, Error>
pub fn connect_to_binder(&self) -> Result<BinderProxy, Error>
Connect to exposed fuchsia.component.Binder protocol of instance, thus triggering it to start. Note: This will only work if the component exposes this protocol in its manifest.
Sourcepub async fn start_with_binder_sync(&self) -> Result<(), Error>
pub async fn start_with_binder_sync(&self) -> Result<(), Error>
Same as connect_to_binder
except that it will block until the
component has started.
Note: This function expects that the instance has not been started yet.
If the instance has been started before this method is invoked, then
this method will block forever waiting for the Started event.
REQUIRED: The manifest of the component executing this code must use
the “started” event_stream.
Sourcepub fn connect_to_protocol_at_exposed_dir<P: DiscoverableProtocolMarker>(
&self,
) -> Result<P::Proxy, Error>
pub fn connect_to_protocol_at_exposed_dir<P: DiscoverableProtocolMarker>( &self, ) -> Result<P::Proxy, Error>
Connect to an instance of a FIDL protocol hosted in the component’s exposed directory`,
Sourcepub fn connect_to_named_protocol_at_exposed_dir<P: DiscoverableProtocolMarker>(
&self,
protocol_name: &str,
) -> Result<P::Proxy, Error>
pub fn connect_to_named_protocol_at_exposed_dir<P: DiscoverableProtocolMarker>( &self, protocol_name: &str, ) -> Result<P::Proxy, Error>
Connect to an instance of a FIDL protocol hosted in the component’s exposed directory`,
Sourcepub fn connect_request_to_protocol_at_exposed_dir<P: DiscoverableProtocolMarker>(
&self,
server_end: ServerEnd<P>,
) -> Result<(), Error>
pub fn connect_request_to_protocol_at_exposed_dir<P: DiscoverableProtocolMarker>( &self, server_end: ServerEnd<P>, ) -> Result<(), Error>
Connects to an instance of a FIDL protocol hosted in the component’s exposed directory
using the given server_end
.
Sourcepub fn connect_request_to_named_protocol_at_exposed_dir(
&self,
protocol_name: &str,
server_end: Channel,
) -> Result<(), Error>
pub fn connect_request_to_named_protocol_at_exposed_dir( &self, protocol_name: &str, server_end: Channel, ) -> Result<(), Error>
Connects to an instance of a FIDL protocol called protocol_name
hosted in the component’s
exposed directory using the given server_end
.
Sourcepub fn get_exposed_dir(&self) -> &DirectoryProxy
pub fn get_exposed_dir(&self) -> &DirectoryProxy
Returns a reference to the component’s read-only exposed directory.
Sourcepub fn destroy_waiter_taken(&self) -> bool
pub fn destroy_waiter_taken(&self) -> bool
Returns true if take_destroy_waiter
has already been called.
Sourcepub fn take_destroy_waiter(&mut self) -> impl Future<Output = Result<(), Error>>
pub fn take_destroy_waiter(&mut self) -> impl Future<Output = Result<(), Error>>
Returns a future which can be awaited on for destruction to complete after the
ScopedInstance
is dropped. Panics if called multiple times.
Sourcepub fn child_name(&self) -> &str
pub fn child_name(&self) -> &str
Return the name of this instance.