From d4b21b0d8e84261ddb1680a9077a9e32f7bc3e79 Mon Sep 17 00:00:00 2001 From: hubertshelley <46239302+hubertshelley@users.noreply.github.com> Date: Tue, 23 May 2023 23:22:52 +0800 Subject: [PATCH] Hubertshelley patch 1 (#6385) * [Silent] add Silent * [Silent] add Silent * Update ci.yml * Update ci.yml --- reviewers.yaml | 2 ++ rust/silent/Cargo.toml | 21 +++++++++++++++++++++ rust/silent/config.yaml | 3 +++ rust/silent/src/main.rs | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 rust/silent/Cargo.toml create mode 100644 rust/silent/config.yaml create mode 100644 rust/silent/src/main.rs diff --git a/reviewers.yaml b/reviewers.yaml index 87fd7684311..f8769e06faa 100644 --- a/reviewers.yaml +++ b/reviewers.yaml @@ -181,6 +181,8 @@ rust: - colinbankier salvo: - chrislearn + silent: + - hubertshelley poem: - sunli829 axum: diff --git a/rust/silent/Cargo.toml b/rust/silent/Cargo.toml new file mode 100644 index 00000000000..c19dac48bae --- /dev/null +++ b/rust/silent/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "server" +version = "0.0.0" +edition = "2021" +authors = ["Hubert Shelley "] + +[dependencies] +async-trait = "0.1.68" +silent = { version = "0.6" } + +[profile.release] +opt-level = 3 +debug = false +debug-assertions = false +overflow-checks = false +lto = true +panic = "abort" +incremental = false +codegen-units = 1 +rpath = false +strip = false diff --git a/rust/silent/config.yaml b/rust/silent/config.yaml new file mode 100644 index 00000000000..f432eabc34f --- /dev/null +++ b/rust/silent/config.yaml @@ -0,0 +1,3 @@ +framework: + github: hubertshelley/silent + version: "0.6" diff --git a/rust/silent/src/main.rs b/rust/silent/src/main.rs new file mode 100644 index 00000000000..5205670c11e --- /dev/null +++ b/rust/silent/src/main.rs @@ -0,0 +1,35 @@ +use std::sync::Arc; +use async_trait::async_trait; +use silent::prelude::*; + +struct Index; + +#[async_trait] +impl Handler for Index { + async fn call(&self, _req: Request) -> Result { + Ok(Response::empty()) + } +} + +fn main() { + let mut user_route = Route::new("user").append( + Route::new("").get( + |req| async move { + req.get_path_params::("id") + } + ), + ); + user_route.get_handler_mut().insert( + Method::POST, + Arc::new(Index), + ); + let mut route = Route::new("") + .append( + user_route + ); + route.get_handler_mut().insert( + Method::GET, + Arc::new(Index), + ); + Server::new().bind("0.0.0.0:3000".parse().unwrap()).bind_route(route).run(); +}