From 0e3d7a2930f649b79f85e043d4c13f930d5a3325 Mon Sep 17 00:00:00 2001 From: Leynos Date: Wed, 18 Jun 2025 14:56:46 +0100 Subject: [PATCH 1/2] Add connection lifecycle documentation --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 89e4503e..68986aff 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,13 @@ reduce this boilerplate through layered abstractions: - **Transport adapter** built on Tokio I/O - **Framing layer** for length‑prefixed or custom frames -- **Connection preamble** with customizable validation callbacks [[docs](docs/preamble-validator.md)] +- **Connection preamble** with customizable validation callbacks \[[docs](docs/preamble-validator.md)\] - Call `with_preamble::()` before registering success or failure callbacks - **Serialization engine** using `bincode` or a `wire-rs` wrapper - **Routing engine** that dispatches messages by ID - **Handler invocation** with extractor support - **Middleware chain** for request/response processing +- **Connection lifecycle hooks** for per-connection setup and teardown These layers correspond to the architecture outlined in the design document【F:docs/rust-binary-router-library-design.md†L292-L344】. @@ -83,9 +84,27 @@ binary protocol server【F:docs/rust-binary-router-library-design.md†L1120-L11 Handlers can return types implementing the `Responder` trait. These values are encoded using the application's configured serializer and written back through the `FrameProcessor`【F:docs/rust-binary-router-library-design.md†L718-L724】. + The included `LengthPrefixedProcessor` illustrates a simple framing strategy based on a big‑endian length prefix【F:docs/rust-binary-router-library-design.md†L1076-L1117】. +## Connection Lifecycle + +`WireframeApp` can run callbacks when a connection opens or closes. The state +produced by `on_connection_setup` is passed to `on_connection_teardown` when the +connection ends. + +```rust +let app = WireframeApp::new() + .unwrap() + .on_connection_setup(|| async { 42u32 }) + .unwrap() + .on_connection_teardown(|state| async move { + println!("closing with {state}"); + }) + .unwrap(); +``` + ## Current Limitations Connection processing is not implemented yet. After the optional From e3510b17d13197da87ca2929431bb73df95e6c47 Mon Sep 17 00:00:00 2001 From: Leynos Date: Wed, 18 Jun 2025 22:42:28 +0100 Subject: [PATCH 2/2] Fix lifecycle docs --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 68986aff..ecabf491 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ reduce this boilerplate through layered abstractions: - **Routing engine** that dispatches messages by ID - **Handler invocation** with extractor support - **Middleware chain** for request/response processing -- **Connection lifecycle hooks** for per-connection setup and teardown +- **[Connection lifecycle hooks](#connection-lifecycle)** for per-connection + setup and teardown These layers correspond to the architecture outlined in the design document【F:docs/rust-binary-router-library-design.md†L292-L344】. @@ -90,19 +91,16 @@ based on a big‑endian length prefix【F:docs/rust-binary-router-library-design ## Connection Lifecycle -`WireframeApp` can run callbacks when a connection opens or closes. The state +`WireframeApp` can run callbacks when a connection is opened or closed. The state produced by `on_connection_setup` is passed to `on_connection_teardown` when the connection ends. ```rust let app = WireframeApp::new() - .unwrap() .on_connection_setup(|| async { 42u32 }) - .unwrap() .on_connection_teardown(|state| async move { println!("closing with {state}"); - }) - .unwrap(); + }); ``` ## Current Limitations