async fn echo_server_mock(
    expected_echo_string: &'static str,
    send_echo_server_called: Arc<Mutex<Option<oneshot::Sender<()>>>>,
    mock_handles: mock::MockHandles,
) -> Result<(), Error> {
    // Create a new ServiceFs to host FIDL protocols from
    let mut fs = fserver::ServiceFs::new();
    let mut tasks = vec![];

    // Add the echo protocol to the ServiceFs
    fs.dir("svc").add_fidl_service(move |mut stream: fecho::EchoRequestStream| {
        let send_echo_server_called = send_echo_server_called.clone();
        tasks.push(fasync::Task::local(async move {
            while let Some(fecho::EchoRequest::EchoString { value, responder }) =
                stream.try_next().await.expect("failed to serve echo service")
            {
                assert_eq!(Some(expected_echo_string.to_string()), value);
                // Send the received string back to the client
                responder.send(value.as_ref().map(|s| &**s)).expect("failed to send echo response");

                // Take the sender from send_echo_server_called and pass a
                // message through it
                send_echo_server_called
                    .lock()
                    .await
                    .take()
                    .unwrap()
                    .send(())
                    .expect("failed to send results");
            }
        }));
    });

    // Run the ServiceFs on the outgoing directory handle from the mock handles
    fs.serve_connection(mock_handles.outgoing_dir.into_channel())?;
    fs.collect::<()>().await;
    Ok(())
}
// [START echo_server_mock]
// A mock echo server implementation, that will crash if it doesn't receive anything other than the
// contents of `expected_echo_str`. It takes and sends a message over `send_echo_server_called`
// once it receives one echo request.
[START echo_server_mock]
A mock echo server implementation, that will crash if it doesn't receive anything other than the
contents of `expected_echo_str`. It takes and sends a message over `send_echo_server_called`
once it receives one echo request.
[ START echo_server_mock ] A mock echo server implementation that will crash if it doesn ' t receive anything other than the contents of ` expected_echo_str ` . It takes and sends a message over ` send_echo_server_called ` once it receives one echo request .
async fn echo_server_mock(
    expected_echo_string: &'static str,
    send_echo_server_called: Arc<Mutex<Option<oneshot::Sender<()>>>>,
    mock_handles: mock::MockHandles,
) -> Result<(), Error> {
    // Create a new ServiceFs to host FIDL protocols from
    let mut fs = fserver::ServiceFs::new();
    let mut tasks = vec![];
    // Add the echo protocol to the ServiceFs
    fs.dir("svc").add_fidl_service(move |mut stream: fecho::EchoRequestStream| {
        let send_echo_server_called = send_echo_server_called.clone();
        tasks.push(fasync::Task::local(async move {
            while let Some(fecho::EchoRequest::EchoString { value, responder }) =
                stream.try_next().await.expect("failed to serve echo service")
            {
                assert_eq!(Some(expected_echo_string.to_string()), value);
                // Send the received string back to the client
                responder.send(value.as_ref().map(|s| &**s)).expect("failed to send echo response");
                // Take the sender from send_echo_server_called and pass a
                // message through it
                send_echo_server_called
                    .lock()
                    .await
                    .take()
                    .unwrap()
                    .send(())
                    .expect("failed to send results");
            }
        }));
    });
    // Run the ServiceFs on the outgoing directory handle from the mock handles
    fs.serve_connection(mock_handles.outgoing_dir.into_channel())?;
    fs.collect::<()>().await;
    Ok(())
}
async fn echo_server_mock ( expected_echo_string : & ' static str , send_echo_server_called : Arc < Mutex < Option < oneshot :: Sender < ( ) > > > > , mock_handles : mock :: MockHandles , ) -> Result < ( ) , Error > { // Create a new ServiceFs to host FIDL protocols from let mut fs = fserver :: ServiceFs :: new ( ) ; let mut tasks = vec ! [ ] ; // Add the echo protocol to the ServiceFs fs . dir ( " " ) . add_fidl_service ( move | mut stream : fecho :: EchoRequestStream | { let send_echo_server_called = send_echo_server_called . clone ( ) ; tasks . push ( fasync :: Task :: local ( async move { while let Some ( fecho :: EchoRequest :: EchoString { value , responder } ) = stream . try_next ( ) . await . expect ( " " ) { assert_eq ! ( Some ( expected_echo_string to_string ( ) ) value ) ; // Send the received string back to the client responder . send ( value . as_ref ( ) . map ( | s | & * * s ) ) . expect ( " " ) ; // Take the sender from send_echo_server_called and pass a // message through it send_echo_server_called . lock ( ) . await . take ( ) . unwrap ( ) . send ( ( ) ) . expect ( " " ) ; } } ) ) ; } ) ; // Run the ServiceFs on the outgoing directory handle from the mock handles fs . serve_connection ( mock_handles . outgoing_dir . into_channel ( ) ) ? ; fs . collect :: < ( ) > ( ) . await ; Ok ( ( ) ) }
[START echo_server_mock]
A mock echo server implementation, that will crash if it doesn't receive anything other than the
contents of `expected_echo_str`.
[ START echo_server_mock ] A mock echo server implementation that will crash if it doesn ' t receive anything other than the contents of ` expected_echo_str ` .
expected_echo_string
&'static str
send_echo_server_called
Arc<Mutex<Option<oneshot::Sender<()>>>>
mock_handles
mock::MockHandles
expected_echo_string
&'static str
send_echo_server_called
Arc<Mutex<Option<oneshot::Sender<()>>>>
mock_handles
mock::MockHandles