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: replace format! with concat! for string literals #2012

Merged
merged 2 commits into from
Dec 9, 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
10 changes: 6 additions & 4 deletions yazi-boot/src/actions/version.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use super::Actions;

impl Actions {
pub(super) fn version() -> String {
format!(
"{} ({} {})",
pub(super) fn version() -> &'static str {
concat!(
env!("CARGO_PKG_VERSION"),
" (",
env!("VERGEN_GIT_SHA"),
env!("VERGEN_BUILD_DATE")
" ",
env!("VERGEN_BUILD_DATE"),
")"
)
}
}
6 changes: 3 additions & 3 deletions yazi-dds/src/body/hey.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{borrow::Cow, collections::HashMap};

use mlua::{ExternalResult, IntoLua, Lua, Value};
use serde::{Deserialize, Serialize};
Expand All @@ -9,13 +9,13 @@ use crate::Peer;
#[derive(Debug, Serialize, Deserialize)]
pub struct BodyHey {
pub peers: HashMap<u64, Peer>,
pub version: String,
pub version: Cow<'static, str>,
}

impl BodyHey {
#[inline]
pub fn owned(peers: HashMap<u64, Peer>) -> Body<'static> {
Self { peers, version: BodyHi::version() }.into()
Self { peers, version: BodyHi::version().into() }.into()
}
}

Expand Down
8 changes: 5 additions & 3 deletions yazi-dds/src/body/hi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ use super::Body;
pub struct BodyHi<'a> {
/// Specifies the kinds of events that the client can handle
pub abilities: HashSet<Cow<'a, str>>,
pub version: String,
pub version: Cow<'static, str>,
}

impl<'a> BodyHi<'a> {
#[inline]
pub fn borrowed(abilities: HashSet<&'a str>) -> Body<'a> {
Self {
abilities: abilities.into_iter().map(Cow::Borrowed).collect(),
version: Self::version(),
version: Self::version().into(),
}
.into()
}

#[inline]
pub fn version() -> String { format!("{} {}", env!("CARGO_PKG_VERSION"), env!("VERGEN_GIT_SHA")) }
pub fn version() -> &'static str {
concat!(env!("CARGO_PKG_VERSION"), " ", env!("VERGEN_GIT_SHA"))
}
}

impl<'a> From<BodyHi<'a>> for Body<'a> {
Expand Down
2 changes: 1 addition & 1 deletion yazi-dds/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Client {
}
}

if version != Some(BodyHi::version()) {
if version.as_deref() != Some(BodyHi::version()) {
bail!(
"Incompatible version (Ya {}, Yazi {})",
BodyHi::version(),
Expand Down
Loading