From fb61d0b446f50fa77714c61fd581493dabb6ebec Mon Sep 17 00:00:00 2001 From: vshengbro <83822098+vshengbro@users.noreply.github.com> Date: Sat, 5 Dec 2026 01:29:33 +0800 Subject: [PATCH 1/2] chore(deps): upgrade ctares dependencies to 11.2.0 and bump to 23.4.1 Upgrade workspace dependencies crate-cli, color-output, lombok-macros, and tokio-broadcast from 11.1.0 to 11.2.0, update the crate-cli CI cache key in .github/workflows/rust.yml, and bump the workspace version and internal crate pins from 23.4.0 to 23.4.1. --- .github/workflows/rust.yml | 2 +- Cargo.toml | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 39a1fb7..fe674d4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -73,7 +73,7 @@ jobs: uses: actions/cache@v3 with: path: ~/.cargo/bin/crate - key: crate-cli-11.1.0-${{ runner.os }} + key: crate-cli-11.2.0-${{ runner.os }} - name: Install crate-cli if: steps.cache_crate_cli.outputs.cache-hit != 'true' run: | diff --git a/Cargo.toml b/Cargo.toml index 9218e9a..81a1daf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "web-programming"] exclude.workspace = true [workspace.package] -version = "23.4.0" +version = "23.4.1" readme = "README.md" edition = "2024" authors = ["root@devhub.vip"] @@ -86,13 +86,13 @@ members = [ ] [workspace.dependencies] -hyperlane = { path = ".", version = "23.4.0" } -http-type = { path = "type", version = "23.4.0" } -hyperlane-core = { path = "core", version = "23.4.0" } -http-request = { path = "request", version = "23.4.0" } -http-compress = { path = "compress", version = "23.4.0" } -http-constant = { path = "constant", version = "23.4.0" } -hyperlane-macros = { path = "macros", version = "23.4.0" } +hyperlane = { path = ".", version = "23.4.1" } +http-type = { path = "type", version = "23.4.1" } +hyperlane-core = { path = "core", version = "23.4.1" } +http-request = { path = "request", version = "23.4.1" } +http-compress = { path = "compress", version = "23.4.1" } +http-constant = { path = "constant", version = "23.4.1" } +hyperlane-macros = { path = "macros", version = "23.4.1" } h3 = "0.0.8" h2 = "0.4.20" @@ -110,18 +110,18 @@ futures = "0.3.34" h3-quinn = "0.0.10" io-uring = "0.7.16" twox-hash = "2.1.5" -crate-cli = "11.1.0" +crate-cli = "11.2.0" inventory = "0.3.25" thiserror = "2.0.21" toml_edit = "0.25.20" serde-xml-rs = "0.8.2" serde_json = "1.0.154" -color-output = "11.1.0" +color-output = "11.2.0" proc-macro2 = "1.0.107" webpki-roots = "1.0.12" -lombok-macros = "11.1.0" +lombok-macros = "11.2.0" serde_urlencoded = "0.7.1" -tokio-broadcast = "11.1.0" +tokio-broadcast = "11.2.0" syn = { version = "3.0.10", features = ["full"] } socket2 = { version = "0.6.5", features = ["all"] } tokio = { version = "1.54.1", features = ["full"] } From fa5e7db6b808674a1cbe3430816fc8886c3f99bd Mon Sep 17 00:00:00 2001 From: vshengbro <83822098+vshengbro@users.noreply.github.com> Date: Sat, 5 Dec 2026 01:50:07 +0800 Subject: [PATCH 2/2] docs(readme): rewrite quick start and macros examples using macros Replace manual server, config, route, header, and body wiring in README.md and macros/README.md with declarative Hyperlane macros (#[hyperlane], #[request_middleware], #[route], #[prologue_macros], and #[epilogue_macros]), verified end-to-end against live HTTP requests. --- README.md | 61 ++++++++++++++++++++++++++++++++++++++++-------- macros/README.md | 20 +++++++++++++--- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1fcc5ca..6587df2 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,28 @@ cargo add hyperlane Replace `src/main.rs` with: ```rust -use hyperlane::{Context, Server, ServerConfig, ServerError, ServerHook, Status, Stream, tokio}; +use hyperlane::*; const ADDRESS: &str = "127.0.0.1:3000"; const ROOT_PATH: &str = "/"; +const GREET_PATH: &str = "/hello/{name}"; const GREETING: &str = "Hello from Hyperlane!\n"; +#[request_middleware] +struct ServerHeader; + +impl ServerHook for ServerHeader { + async fn new(_: &mut Stream, _: &mut Context) -> Self { + Self + } + + #[prologue_macros(response_header(SERVER => HYPERLANE))] + async fn handle(self, _: &mut Stream, ctx: &mut Context) -> Status { + Status::Continue + } +} + +#[route(ROOT_PATH)] struct Hello; impl ServerHook for Hello { @@ -64,35 +80,60 @@ impl ServerHook for Hello { Self } - #[hyperlane::send] + #[prologue_macros( + is_get_method, + response_status_code(200), + response_header(CONTENT_TYPE => TEXT_PLAIN), + response_body(GREETING) + )] + #[epilogue_macros(try_send)] async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status { - ctx.get_mut_response().set_body(GREETING); Status::Reject } } +#[route(GREET_PATH)] +struct Greet; + +impl ServerHook for Greet { + async fn new(_: &mut Stream, _: &mut Context) -> Self { + Self + } + + #[prologue_macros( + is_get_method, + route_param("name" => name), + response_status_code(200), + response_header(CONTENT_TYPE => TEXT_PLAIN), + response_body(&format!("Hello, {name}!\n")) + )] + #[epilogue_macros(try_send)] + async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status { + Status::Reject + } +} + +#[hyperlane(server: Server, config: ServerConfig)] #[tokio::main] async fn main() -> Result<(), Box> { - let mut config: ServerConfig = ServerConfig::default(); config.set_address(ADDRESS); + server.server_config(config); - let mut server: Server = Server::default(); - server.server_config(config).route::(ROOT_PATH); - - let control = server.run().await?; + let control: ServerControlHook = server.run().await?; println!("Listening on http://{ADDRESS}"); control.wait().await; Ok(()) } ``` -Run `cargo run` and query the endpoint: +Run `cargo run` and query the endpoints: ```sh curl -fsS http://127.0.0.1:3000/ +curl -fsS http://127.0.0.1:3000/hello/hyperlane ``` -`#[hyperlane::send]` serializes and flushes the response built by the hook; `Status::Reject` stops the remaining pipeline so downstream hooks do not send a duplicate response. +`#[request_middleware]` and `#[route]` register hooks automatically via inventory; `#[hyperlane(server: Server, config: ServerConfig)]` initializes `server` with every discovered hook and constructs `config`; `#[prologue_macros(...)]` and `#[epilogue_macros(try_send)]` guard HTTP methods, extract route parameters, populate status/headers/body, and flush the response without manual boilerplate. --- diff --git a/macros/README.md b/macros/README.md index feadf77..ed16426 100644 --- a/macros/README.md +++ b/macros/README.md @@ -31,8 +31,9 @@ cargo add hyperlane-macros ## Usage ```rust -use hyperlane::{Context, ServerHook, Status, Stream}; +use hyperlane::*; +#[route("/health")] struct HealthRoute; impl ServerHook for HealthRoute { @@ -40,12 +41,25 @@ impl ServerHook for HealthRoute { Self } - #[hyperlane::send] + #[prologue_macros( + is_get_method, + response_status_code(200), + response_header(CONTENT_TYPE => TEXT_PLAIN), + response_body("ok") + )] + #[epilogue_macros(try_send)] async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status { - ctx.get_mut_response().set_body("ok"); Status::Reject } } + +#[hyperlane(server: Server, config: ServerConfig)] +async fn start_server() -> Result<(), Box> { + config.set_address("127.0.0.1:3000"); + server.server_config(config); + server.run().await?.wait().await; + Ok(()) +} ``` ## Verification