/// This is an indefinite loop that is run inside a actor component. Clients use the Actor
/// protocol to run test actions.
///
/// This method will serve the Actor protocol over its outgoing directory and wait for
/// exactly one client to connect.
///
/// NOTE: This method takes and serves the process' outgoing directory handle.
/// This handle should not be taken before this method is invoked.
///
/// NOTE: The actor library expects exactly one connection to the Actor protocol in this method.
This is an indefinite loop that is run inside a actor component. Clients use the Actor
protocol to run test actions.

This method will serve the Actor protocol over its outgoing directory and wait for
exactly one client to connect.

This method takes and serves the process' outgoing directory handle.
This handle should not be taken before this method is invoked.

The actor library expects exactly one connection to the Actor protocol in this method.
This is an indefinite loop that is run inside a actor component . Clients use the Actor protocol to run test actions . This method will serve the Actor protocol over its outgoing directory and wait for exactly one client to connect . This method takes and serves the process ' outgoing directory handle . This handle should not be taken before this method is invoked . The actor library expects exactly one connection to the Actor protocol in this method .
pub async fn actor_loop<D>(mut data: D, actions: Vec<Action<D>>) -> Result<()> {
    let mut service_fs = ServiceFs::new();
    service_fs.dir("svc").add_fidl_service(OutgoingProtocols::Actor);
    service_fs.take_and_serve_directory_handle()?;
    // Wait for a client to connect
    let OutgoingProtocols::Actor(mut stream) = service_fs
        .next()
        .await
        .ok_or(format_err!("Could not get next connection to Actor protocol"))?;
    while let Some(request) = stream
        .try_next()
        .await
        .map_err(|e| format_err!("FIDL error in call to Actor protocol: {}", e))?
    {
        match request {
            ActorRequest::GetActions { responder } => {
                let (client_end, mut stream) = create_request_stream::<ActionIteratorMarker>()?;
                responder.send(client_end)?;
                let mut iter = actions.iter().map(|c| c.to_fidl());
                while let Some(ActionIteratorRequest::GetNext { responder }) =
                    stream.try_next().await?
                {
                    let mut bytes_used: usize = 32;
                    let mut action_count = 0;
                    // Determine how many actions can be sent in a single FIDL message,
                    // accounting for the header and `Action` size.
                    for action in iter.clone() {
                        bytes_used += action.measure().num_bytes;
                        if bytes_used > ZX_CHANNEL_MAX_MSG_BYTES as usize {
                            break;
                        }
                        action_count += 1;
                    }
                    responder.send(&mut iter.by_ref().take(action_count))?;
                    // There are no more actions left to return. The client has gotten
                    // an empty response, so they also know that there are no more actions.
                    // Close this channel.
                    if action_count == 0 {
                        break;
                    }
                }
            }
            ActorRequest::Run { action_name, seed, responder } => {
                if let Some(action) = actions.iter().find(|action| action.name == action_name) {
                    let rng = SmallRng::seed_from_u64(seed);
                    if let Err(e) = (action.run)(&mut data, rng).await {
                        // The action failed. Return the error chain as an unstructured
                        // error message.
                        let chain: Vec<String> = e.chain().map(|c| c.to_string()).collect();
                        let chain = chain.join(" -> ");
                        responder.send(Some(&mut Error::ErrorString(chain)))?;
                    } else {
                        // The action succeeded
                        responder.send(None)?;
                    }
                } else {
                    responder
                        .send(Some(&mut Error::ErrorString("Invalid action name".to_string())))?;
                }
            }
        }
    }
    Ok(())
}
pub async fn actor_loop < D > ( mut data : D , actions : Vec < Action < D > > ) -> Result < ( ) > { let mut service_fs = ServiceFs :: new ( ) ; service_fs . dir ( " " ) . add_fidl_service ( OutgoingProtocols :: Actor ) ; service_fs . take_and_serve_directory_handle ( ) ? ; // Wait for a client to connect let OutgoingProtocols :: Actor ( mut stream ) = service_fs . next ( ) . await . ok_or ( format_err ! ( " " ) ) ? ; while let Some ( request ) = stream . try_next ( ) . await . map_err ( | e | format_err ! ( " " e ) ) ? { match request { ActorRequest :: GetActions { responder } => { let ( client_end , mut stream ) = create_request_stream :: < ActionIteratorMarker > ( ) ? ; responder . send ( client_end ) ? ; let mut iter = actions . iter ( ) . map ( | c | c . to_fidl ( ) ) ; while let Some ( ActionIteratorRequest :: GetNext { responder } ) = stream . try_next ( ) . await ? { let mut bytes_used : usize = 32 ; let mut action_count = 0 ; // Determine how many actions can be sent in a single FIDL message, // accounting for the header and `Action` size. for action in iter . clone ( ) { bytes_used += action . measure ( ) . num_bytes ; if bytes_used > ZX_CHANNEL_MAX_MSG_BYTES as usize { break ; } action_count += 1 ; } responder . send ( & mut iter . by_ref ( ) . take ( action_count ) ) ? ; // There are no more actions left to return. The client has gotten // an empty response, so they also know that there are no more actions. // Close this channel. if action_count == 0 { break ; } } } ActorRequest :: Run { action_name , seed , responder } => { if let Some ( action ) = actions . iter ( ) . find ( | action | action . name == action_name ) { let rng = SmallRng :: seed_from_u64 ( seed ) ; if let Err ( e ) = ( action . run ) ( & mut data , rng ) . await { // The action failed. Return the error chain as an unstructured // error message. let chain : Vec < String > = e . chain ( ) . map ( | c | c . to_string ( ) ) . collect ( ) ; let chain = chain . join ( " " ) ; responder . send ( Some ( & mut Error :: ErrorString ( chain ) ) ) ? ; } else { // The action succeeded responder . send ( None ) ? ; } } else { responder . send ( Some ( & mut Error :: ErrorString ( " " . to_string ( ) ) ) ) ? ; } } } } Ok ( ( ) ) }
This is an indefinite loop that is run inside a actor component.
This is an indefinite loop that is run inside a actor component .
data
D
actions
Vec<Action<D>>