Getting started

This tutorial gets a minimal TCP service running with the reference length-delimited protocol.

Add nacelle

In this workspace, the umbrella crate is nacelle. It re-exports the transport crates and owns the reference protocol:

#![allow(unused)]
fn main() {
use nacelle::prelude::*;
}

Build a handler

Handlers receive a NacelleRequest and return a NacelleResponse.

#![allow(unused)]
fn main() {
let handler = handler_fn(|mut request: NacelleRequest| async move {
    while let Some(chunk) = request.body.next_chunk().await {
        let _ = chunk?;
    }

    Ok(NacelleResponse::tcp_bytes("ok"))
});
}

Start the app

#![allow(unused)]
fn main() {
let addr = "127.0.0.1:8080".parse().map_err(NacelleError::protocol)?;
let protocols = NacelleProtocols::new()
    .tcp::<FrameRequest, _>("echo", addr, LengthDelimitedProtocol);

NacelleApp::new(handler)
    .with_telemetry(NacelleTelemetry::default())
    .with_ctrl_c_shutdown()
    .serve(protocols)
    .await?;
Ok::<(), NacelleError>(())
}

Next steps