From 80222c271f66111a3a3d84ac65d007ffe14789df Mon Sep 17 00:00:00 2001 From: Integral Date: Sat, 21 Dec 2024 16:46:32 +0800 Subject: [PATCH 1/2] refactor: return &'static str when returning String is unnecessary --- libs/api/src/path.rs | 8 ++++---- libs/signal/src/lib.rs | 18 +++++++++--------- liveion/src/route/strategy.rs | 2 +- liveion/src/route/stream.rs | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libs/api/src/path.rs b/libs/api/src/path.rs index d89dd9c3..dfe50952 100644 --- a/libs/api/src/path.rs +++ b/libs/api/src/path.rs @@ -30,10 +30,10 @@ pub fn cascade(stream: &str) -> String { format!("/api/cascade/{}", stream) } -pub fn streams_sse() -> String { - "/api/sse/streams".to_string() +pub fn streams_sse() -> &'static str { + "/api/sse/streams" } -pub fn strategy() -> String { - "/api/strategy/".to_string() +pub fn strategy() -> &'static str { + "/api/strategy/" } diff --git a/libs/signal/src/lib.rs b/libs/signal/src/lib.rs index 4a66d35b..5aea199e 100644 --- a/libs/signal/src/lib.rs +++ b/libs/signal/src/lib.rs @@ -2,7 +2,7 @@ /// Waits for a signal that requests a graceful shutdown, like SIGTERM or SIGINT. #[cfg(unix)] -async fn wait_for_signal_impl() -> String { +async fn wait_for_signal_impl() -> &'static str { use tokio::signal::unix::{signal, SignalKind}; // Infos here: @@ -11,14 +11,14 @@ async fn wait_for_signal_impl() -> String { let mut signal_interrupt = signal(SignalKind::interrupt()).unwrap(); tokio::select! { - _ = signal_terminate.recv() => "SIGTERM".to_string(), - _ = signal_interrupt.recv() => "SIGINT".to_string(), + _ = signal_terminate.recv() => "SIGTERM", + _ = signal_interrupt.recv() => "SIGINT", } } /// Waits for a signal that requests a graceful shutdown, Ctrl-C (SIGINT). #[cfg(windows)] -async fn wait_for_signal_impl() -> String { +async fn wait_for_signal_impl() -> &'static str { use tokio::signal::windows; // Infos here: @@ -29,15 +29,15 @@ async fn wait_for_signal_impl() -> String { let mut signal_shutdown = windows::ctrl_shutdown().unwrap(); tokio::select! { - _ = signal_c.recv() => "CTRL_C".to_string(), - _ = signal_break.recv() => "CTRL_BREAK".to_string(), - _ = signal_close.recv() => "CTRL_CLOSE".to_string(), - _ = signal_shutdown.recv() => "CTRL_SHUTDOWN".to_string(), + _ = signal_c.recv() => "CTRL_C", + _ = signal_break.recv() => "CTRL_BREAK", + _ = signal_close.recv() => "CTRL_CLOSE", + _ = signal_shutdown.recv() => "CTRL_SHUTDOWN", } } /// Registers signal handlers and waits for a signal that /// indicates a shutdown request. -pub async fn wait_for_stop_signal() -> String { +pub async fn wait_for_stop_signal() -> &'static str { wait_for_signal_impl().await } diff --git a/liveion/src/route/strategy.rs b/liveion/src/route/strategy.rs index 52a93b68..89176976 100644 --- a/liveion/src/route/strategy.rs +++ b/liveion/src/route/strategy.rs @@ -4,7 +4,7 @@ use axum::routing::get; use axum::{Json, Router}; pub fn route() -> Router { - Router::new().route(&api::path::strategy(), get(show)) + Router::new().route(api::path::strategy(), get(show)) } async fn show( diff --git a/liveion/src/route/stream.rs b/liveion/src/route/stream.rs index ef6fa154..53c81acc 100644 --- a/liveion/src/route/stream.rs +++ b/liveion/src/route/stream.rs @@ -18,7 +18,7 @@ pub fn route() -> Router { .route(&api::path::streams(":stream"), get(show)) .route(&api::path::streams(":stream"), post(create)) .route(&api::path::streams(":stream"), delete(destroy)) - .route(&api::path::streams_sse(), get(sse)) + .route(api::path::streams_sse(), get(sse)) } async fn index( From 520859c3adcc63b7f996b2c7f0eb5b01f8217ce0 Mon Sep 17 00:00:00 2001 From: Integral Date: Sat, 21 Dec 2024 16:54:36 +0800 Subject: [PATCH 2/2] Sign CLA --- .github/CLA.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CLA.md b/.github/CLA.md index 847d8d70..17d8c8d3 100644 --- a/.github/CLA.md +++ b/.github/CLA.md @@ -54,3 +54,4 @@ Example: - Rocket Aaron, @rocka, 2024/04/22 - Likai Zhao, @agougougoua, 2024/05/09 - Yihan Wen, @udrs, 2024/6/21 +- George Hu, @Integral-Tech, 2024/12/21