Skip to content

Commit

Permalink
refactor: replace format! with concat! for string literals (#2012)
Browse files Browse the repository at this point in the history
Co-authored-by: sxyazi <[email protected]>
  • Loading branch information
Integral-Tech and sxyazi authored Dec 9, 2024
1 parent 62ac224 commit a743488
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
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

0 comments on commit a743488

Please sign in to comment.