Skip to content

Commit

Permalink
refactor: return &'static str when returning String is unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech committed Dec 21, 2024
1 parent 681088c commit 80222c2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
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/"
}
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

0 comments on commit 80222c2

Please sign in to comment.