Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
yuma140902 committed Sep 4, 2024
1 parent 4fe41ef commit c9c85f0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::Parser;
use tempura::cli::{Cli, Commands};
use tracing::debug;

fn verbose_to_level(verbose: u8) -> tracing::Level {
const fn verbose_to_level(verbose: u8) -> tracing::Level {
if verbose == 0 {
#[cfg(debug_assertions)]
return tracing::Level::DEBUG;
Expand Down
7 changes: 4 additions & 3 deletions src/pipeline/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl<'a> Job<'a> {
let mut output_file = fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.append(false)
.open(&self.output_path)
.with_context(|| {
Expand All @@ -66,15 +67,15 @@ impl<'a> Job<'a> {
Ok(())
}

pub fn pipeline(&self) -> &Pipeline {
pub const fn pipeline(&self) -> &Pipeline {
self.pipeline
}

pub fn input_path(&self) -> &PathBuf {
pub const fn input_path(&self) -> &PathBuf {
&self.input_path
}

pub fn output_path(&self) -> &PathBuf {
pub const fn output_path(&self) -> &PathBuf {
&self.output_path
}
}
12 changes: 4 additions & 8 deletions src/string_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ pub enum StringMatcher {
impl StringMatcher {
pub fn is_match(&self, string: &str) -> bool {
match self {
StringMatcher::Regex { regex } => regex.is_match(string),
StringMatcher::Not { matcher } => !matcher.is_match(string),
StringMatcher::All { matchers } => {
matchers.iter().all(|matcher| matcher.is_match(string))
}
StringMatcher::Any { matchers } => {
matchers.iter().any(|matcher| matcher.is_match(string))
}
Self::Regex { regex } => regex.is_match(string),
Self::Not { matcher } => !matcher.is_match(string),
Self::All { matchers } => matchers.iter().all(|matcher| matcher.is_match(string)),
Self::Any { matchers } => matchers.iter().any(|matcher| matcher.is_match(string)),
}
}
}
6 changes: 3 additions & 3 deletions src/transformer/template_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct TemplateRenderer {
pub current_directory: Option<CurrentDirectory>,
}

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(tag = "type")]
pub enum CurrentDirectory {
EntryDirectory,
Expand Down Expand Up @@ -53,8 +53,8 @@ impl Transformer for TemplateRenderer {
)
}

let current_directory: Option<String> = if let Some(CurrentDirectory::EntryDirectory) =
&self.current_directory
let current_directory: Option<String> = if self.current_directory
== Some(CurrentDirectory::EntryDirectory)
{
match store.get("___entry_directory") {
Some(Value::JSON(serde_json::Value::String(entry_dir))) => Some(entry_dir.into()),
Expand Down
13 changes: 6 additions & 7 deletions src/value.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
use handlebars::Template;

#[derive(Debug, Clone)]
/// [`Value`] is data read from a file by the [`Loader`](crate::loader::Loader).
/// Conceptually, it is the same as JSON.
/// It is hierarchical and has types such as object, string, and numeric.

#[derive(Debug, Clone)]
pub enum Value {
Bytes(Vec<u8>),
Template(Template),
JSON(serde_json::Value),
}

impl Value {
pub fn get_type_name(&self) -> &'static str {
pub const fn get_type_name(&self) -> &'static str {
match self {
Value::Bytes(_) => "bytes",
Value::JSON(json) => get_json_type_name(json),
Value::Template(_) => "template",
Self::Bytes(_) => "bytes",
Self::JSON(json) => get_json_type_name(json),
Self::Template(_) => "template",
}
}
}

fn get_json_type_name(json: &serde_json::Value) -> &'static str {
const fn get_json_type_name(json: &serde_json::Value) -> &'static str {
match json {
serde_json::Value::Null => "null",
serde_json::Value::Bool(_) => "bool",
Expand Down

0 comments on commit c9c85f0

Please sign in to comment.