async fn echo_server_mock(
    expected_echo_string: &'static str,
    send_echo_server_called: mpsc::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 mut 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");

                // Use send_echo_server_called to report back that we successfully received a
                // message and it aligned with our expectations
                send_echo_server_called.send(()).await.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: mpsc::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 mut 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");
                // Use send_echo_server_called to report back that we successfully received a
                // message and it aligned with our expectations
                send_echo_server_called.send(()).await.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 : mpsc :: 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 mut 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 ( " " ) ; // Use send_echo_server_called to report back that we successfully received a // message and it aligned with our expectations send_echo_server_called . send ( ( ) ) . await . 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
mpsc::Sender<()>
mock_handles
mock::MockHandles
expected_echo_string
&'static str
send_echo_server_called
mpsc::Sender<()>
mock_handles
mock::MockHandles