Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: return &'static str when returning String is unnecessary #261

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CLA.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions libs/api/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Integral-Tech marked this conversation as resolved.
Show resolved Hide resolved
}
18 changes: 9 additions & 9 deletions libs/signal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion liveion/src/route/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::routing::get;
use axum::{Json, Router};

pub fn route() -> Router<AppState> {
Router::new().route(&api::path::strategy(), get(show))
Router::new().route(api::path::strategy(), get(show))
}

async fn show(
Expand Down
2 changes: 1 addition & 1 deletion liveion/src/route/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn route() -> Router<AppState> {
.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(
Expand Down
Loading