Skip to content

Commit

Permalink
fix cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
baoyachi committed Mar 3, 2024
1 parent bd6893f commit e312220
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ time = { version = "0.3.11", features = ["formatting", "local-offset", "parsing"
#! Optional Dependencies:

## Use `libgit2` as a backend for git operations
git2 = { version = "0.18.0", default-features = false, optional = true }
git2 = { version = "0.18.2", default-features = false, optional = true }

## Better support for querying the local system time
tzdb = { version = "0.6.0", optional = true, default-features = false, features = ["local"] }
Expand Down
16 changes: 6 additions & 10 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};

/// `shadow-rs` build constant identifiers.
pub type ShadowConst = &'static str;

pub trait ShadowGen {
fn gen_const(&self) -> BTreeMap<ShadowConst, ConstVal>;
}

/// Serialized values for build constants.
#[derive(Debug, Clone)]
pub struct ConstVal {
Expand Down Expand Up @@ -47,12 +43,12 @@ pub enum ConstType {
Bool,
}

impl ToString for ConstType {
fn to_string(&self) -> String {
impl Display for ConstType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ConstType::OptStr => "Option<&str>".to_string(),
ConstType::Str => "&str".to_string(),
ConstType::Bool => "bool".to_string(),
ConstType::OptStr => write!(f, "Option<&str>"),
ConstType::Str => write!(f, "&str"),
ConstType::Bool => write!(f, "bool"),
}
}
}
12 changes: 7 additions & 5 deletions src/ci.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Display, Formatter};

/// [`CiType`] holds the types of CI environment that `shadow-rs` can detect.
#[derive(Debug)]
pub enum CiType {
Expand All @@ -13,12 +15,12 @@ impl Default for CiType {
}
}

impl ToString for CiType {
fn to_string(&self) -> String {
impl Display for CiType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
CiType::Github => "github".into(),
CiType::Gitlab => "gitlab".into(),
_ => "none".into(),
CiType::Github => write!(f, "github"),
CiType::Gitlab => write!(f, "gitlab"),
_ => write!(f, "none"),
}
}
}
1 change: 0 additions & 1 deletion src/err.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::convert::From;
use std::error::Error;
use std::error::Error as StdError;
use std::fmt::{Display, Formatter};
Expand Down
3 changes: 1 addition & 2 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ fn filter_git_dirty_stage(dirty_files: Vec<String>, staged_files: Vec<String>) -
mod tests {
use super::*;
use crate::get_std_env;
use std::path::Path;

#[test]
fn test_git() {
Expand All @@ -535,7 +534,7 @@ mod tests {

#[test]
fn test_current_branch() {
if get_std_env().get("GITHUB_REF").is_some() {
if get_std_env().contains_key("GITHUB_REF") {
return;
}
#[cfg(feature = "git2")]
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,22 @@ impl Shadow {
#[allow(clippy::all)]\n\
pub const {} :{} = r#\"{}\"#;",
shadow_const.to_ascii_uppercase(),
ConstType::Str.to_string(),
ConstType::Str,
""
),
ConstType::Str => format!(
"#[allow(dead_code)]\n\
#[allow(clippy::all)]\n\
pub const {} :{} = r#\"{}\"#;",
shadow_const.to_ascii_uppercase(),
ConstType::Str.to_string(),
ConstType::Str,
val.v
),
ConstType::Bool => format!(
"#[allow(dead_code)]\n\
pub const {} :{} = {};",
shadow_const.to_ascii_uppercase(),
ConstType::Bool.to_string(),
ConstType::Bool,
val.v.parse::<bool>().unwrap()
),
};
Expand Down

0 comments on commit e312220

Please sign in to comment.