diff --git a/crates/gh-workflow/src/cargo.rs b/crates/gh-workflow/src/cargo.rs index eb9ad53..0affe43 100644 --- a/crates/gh-workflow/src/cargo.rs +++ b/crates/gh-workflow/src/cargo.rs @@ -25,8 +25,8 @@ pub struct Cargo { impl Cargo { /// Creates a new `Cargo` instance with the specified command. - pub fn new(cmd: T) -> Cargo { - Cargo { + pub fn new(cmd: T) -> Self { + Self { command: cmd.to_string(), id: Default::default(), name: Default::default(), diff --git a/crates/gh-workflow/src/container.rs b/crates/gh-workflow/src/container.rs index 7123578..71dd3c7 100644 --- a/crates/gh-workflow/src/container.rs +++ b/crates/gh-workflow/src/container.rs @@ -78,7 +78,7 @@ impl Volume { pub fn new(volume_str: &str) -> Option { let parts: Vec<&str> = volume_str.split(':').collect(); if parts.len() == 2 { - Some(Volume { + Some(Self { source: parts[0].to_string(), destination: parts[1].to_string(), }) diff --git a/crates/gh-workflow/src/ctx.rs b/crates/gh-workflow/src/ctx.rs index d793052..0652e2a 100644 --- a/crates/gh-workflow/src/ctx.rs +++ b/crates/gh-workflow/src/ctx.rs @@ -43,7 +43,7 @@ enum Step { impl Context { fn new() -> Self { - Context { marker: PhantomData, step: Step::Root } + Self { marker: PhantomData, step: Step::Root } } fn select(&self, path: impl Into) -> Context { @@ -56,7 +56,7 @@ impl Context { } } - pub fn eq(&self, other: Context) -> Context { + pub fn eq(&self, other: Self) -> Context { Context { marker: Default::default(), step: Step::Eq { @@ -66,7 +66,7 @@ impl Context { } } - pub fn and(&self, other: Context) -> Context { + pub fn and(&self, other: Self) -> Context { Context { marker: Default::default(), step: Step::And { @@ -76,7 +76,7 @@ impl Context { } } - pub fn or(&self, other: Context) -> Context { + pub fn or(&self, other: Self) -> Context { Context { marker: Default::default(), step: Step::Or { @@ -88,8 +88,8 @@ impl Context { } impl Context { - pub fn concat(&self, other: Context) -> Context { - Context { + pub fn concat(&self, other: Self) -> Self { + Self { marker: Default::default(), step: Step::Concat { left: Box::new(self.step.clone()), @@ -199,27 +199,27 @@ impl Context { impl fmt::Display for Step { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Step::Root => write!(f, ""), - Step::Select { name, object } => { - if matches!(**object, Step::Root) { + Self::Root => write!(f, ""), + Self::Select { name, object } => { + if matches!(**object, Self::Root) { write!(f, "{name}") } else { write!(f, "{object}.{name}") } } - Step::Eq { left, right } => { + Self::Eq { left, right } => { write!(f, "{left} == {right}") } - Step::And { left, right } => { + Self::And { left, right } => { write!(f, "{left} && {right}") } - Step::Or { left, right } => { + Self::Or { left, right } => { write!(f, "{left} || {right}") } - Step::Literal(value) => { + Self::Literal(value) => { write!(f, "'{value}'") } - Step::Concat { left, right } => { + Self::Concat { left, right } => { write!(f, "{left}{right}") } } @@ -234,13 +234,13 @@ impl fmt::Display for Context { impl From> for Expression { fn from(value: Context) -> Self { - Expression::new(value.to_string()) + Self::new(value.to_string()) } } impl> From for Context { fn from(value: T) -> Self { - Context { + Self { marker: Default::default(), step: Step::Literal(value.into()), } diff --git a/crates/gh-workflow/src/env.rs b/crates/gh-workflow/src/env.rs index f2a9a20..5dd5212 100644 --- a/crates/gh-workflow/src/env.rs +++ b/crates/gh-workflow/src/env.rs @@ -15,7 +15,7 @@ pub struct Env(pub IndexMap); impl From> for Env { /// Converts an `IndexMap` into an `Env`. fn from(value: IndexMap) -> Self { - Env(value) + Self(value) } } @@ -27,12 +27,12 @@ impl Env { "GITHUB_TOKEN".to_string(), Value::from("${{ secrets.GITHUB_TOKEN }}"), ); - Env(map) + Self(map) } /// Creates a new `Env` with a specified key-value pair. pub fn new>(key: K, value: V) -> Self { - Env::default().add(key, value) + Self::default().add(key, value) } /// Adds an environment variable to the `Env`. @@ -48,6 +48,6 @@ impl From<(S1, S2)> for Env { fn from(value: (S1, S2)) -> Self { let mut index_map: IndexMap = IndexMap::new(); index_map.insert(value.0.to_string(), Value::String(value.1.to_string())); - Env(index_map) + Self(index_map) } } diff --git a/crates/gh-workflow/src/job.rs b/crates/gh-workflow/src/job.rs index 409606a..5b1d0db 100644 --- a/crates/gh-workflow/src/job.rs +++ b/crates/gh-workflow/src/job.rs @@ -23,7 +23,7 @@ where { /// Converts a value into a `RunsOn` instance. fn from(value: T) -> Self { - RunsOn(value.into()) + Self(value.into()) } } diff --git a/crates/gh-workflow/src/release_plz.rs b/crates/gh-workflow/src/release_plz.rs index a8ea30a..ef9c14d 100644 --- a/crates/gh-workflow/src/release_plz.rs +++ b/crates/gh-workflow/src/release_plz.rs @@ -50,8 +50,8 @@ pub enum Command { impl std::fmt::Display for Command { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Command::ReleasePR => write!(f, "release-pr"), - Command::Release => write!(f, "release"), + Self::ReleasePR => write!(f, "release-pr"), + Self::Release => write!(f, "release"), } } } @@ -65,8 +65,8 @@ pub enum Backend { impl std::fmt::Display for Backend { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Backend::GitHub => write!(f, "github"), - Backend::Gitea => write!(f, "gitea"), + Self::GitHub => write!(f, "github"), + Self::Gitea => write!(f, "gitea"), } } } diff --git a/crates/gh-workflow/src/rust_flag.rs b/crates/gh-workflow/src/rust_flag.rs index 5c03499..346c557 100644 --- a/crates/gh-workflow/src/rust_flag.rs +++ b/crates/gh-workflow/src/rust_flag.rs @@ -23,39 +23,39 @@ pub enum Lint { } impl core::ops::Add for RustFlags { - type Output = RustFlags; + type Output = Self; fn add(self, rhs: Self) -> Self::Output { - RustFlags::Combine(Box::new(self), Box::new(rhs)) + Self::Combine(Box::new(self), Box::new(rhs)) } } impl RustFlags { pub fn allow(name: S) -> Self { - RustFlags::Lint(name.to_string(), Lint::Allow) + Self::Lint(name.to_string(), Lint::Allow) } pub fn warn(name: S) -> Self { - RustFlags::Lint(name.to_string(), Lint::Warn) + Self::Lint(name.to_string(), Lint::Warn) } pub fn deny(name: S) -> Self { - RustFlags::Lint(name.to_string(), Lint::Deny) + Self::Lint(name.to_string(), Lint::Deny) } pub fn forbid(name: S) -> Self { - RustFlags::Lint(name.to_string(), Lint::Forbid) + Self::Lint(name.to_string(), Lint::Forbid) } pub fn codegen(name: S) -> Self { - RustFlags::Lint(name.to_string(), Lint::Codegen) + Self::Lint(name.to_string(), Lint::Codegen) } } impl Display for RustFlags { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { - RustFlags::Lint(name, lint) => match lint { + Self::Lint(name, lint) => match lint { Lint::Allow => write!(f, "-A{name}"), Lint::Warn => write!(f, "-W{name}"), Lint::Deny => write!(f, "-D{name}"), @@ -63,7 +63,7 @@ impl Display for RustFlags { Lint::Codegen => write!(f, "-C{name}"), Lint::Experiment => write!(f, "-Z{name}"), }, - RustFlags::Combine(lhs, rhs) => write!(f, "{lhs} {rhs}"), + Self::Combine(lhs, rhs) => write!(f, "{lhs} {rhs}"), } } } @@ -72,6 +72,6 @@ impl From for Env { fn from(value: RustFlags) -> Self { let mut env = IndexMap::default(); env.insert("RUSTFLAGS".to_string(), Value::from(value.to_string())); - Env::from(env) + Self::from(env) } } diff --git a/crates/gh-workflow/src/step.rs b/crates/gh-workflow/src/step.rs index cfd6b20..e003722 100644 --- a/crates/gh-workflow/src/step.rs +++ b/crates/gh-workflow/src/step.rs @@ -73,7 +73,7 @@ pub struct Input(#[serde(skip_serializing_if = "IndexMap::is_empty")] pub IndexM impl From> for Input { /// Converts an `IndexMap` into an `Input`. fn from(value: IndexMap) -> Self { - Input(value) + Self(value) } } @@ -162,7 +162,7 @@ pub struct StepValue { impl StepValue { /// Creates a new `StepValue` that runs the provided shell command. pub fn run(cmd: T) -> Self { - StepValue { run: Some(cmd.to_string()), ..Default::default() } + Self { run: Some(cmd.to_string()), ..Default::default() } } /// Creates a new `StepValue` that uses an action. @@ -171,7 +171,7 @@ impl StepValue { repo: Repo, version: Version, ) -> Self { - StepValue { + Self { uses: Some(format!( "{}/{}@{}", owner.to_string(), @@ -197,7 +197,7 @@ impl Step { impl Step<()> { pub fn new(name: impl ToString) -> Self { - Step { + Self { value: StepValue::default().name(name.to_string()), marker: Default::default(), } @@ -222,7 +222,7 @@ impl Step<()> { /// Represents a step that uses an action. impl Step { /// Creates a step pointing to the default GitHub's Checkout Action. - pub fn checkout() -> Step { + pub fn checkout() -> Self { Step::new("Checkout Code").uses("actions", "checkout", "v5") } @@ -246,13 +246,13 @@ impl From<(S1, S2)> for Input { fn from(value: (S1, S2)) -> Self { let mut index_map: IndexMap = IndexMap::new(); index_map.insert(value.0.to_string(), Value::String(value.1.to_string())); - Input(index_map) + Self(index_map) } } impl Step { - pub fn toolchain() -> Step { - Step { value: Default::default(), marker: Toolchain::default() } + pub fn toolchain() -> Self { + Self { value: Default::default(), marker: Toolchain::default() } } pub fn add_version(mut self, version: Version) -> Self { diff --git a/crates/gh-workflow/src/toolchain.rs b/crates/gh-workflow/src/toolchain.rs index 1e652d5..ebc0c88 100644 --- a/crates/gh-workflow/src/toolchain.rs +++ b/crates/gh-workflow/src/toolchain.rs @@ -17,16 +17,16 @@ pub enum Version { impl Display for Version { fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { match self { - Version::Stable => write!(f, "stable"), - Version::Nightly => write!(f, "nightly"), - Version::Custom(s) => write!(f, "{}.{}.{}", s.0, s.1, s.2), + Self::Stable => write!(f, "stable"), + Self::Nightly => write!(f, "nightly"), + Self::Custom(s) => write!(f, "{}.{}.{}", s.0, s.1, s.2), } } } impl Version { pub fn new(major: u64, minor: u64, patch: u64) -> Self { - Version::Custom((major, minor, patch)) + Self::Custom((major, minor, patch)) } } @@ -40,9 +40,9 @@ pub enum Component { impl Display for Component { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let val = match self { - Component::Clippy => "clippy", - Component::Rustfmt => "rustfmt", - Component::RustDoc => "rust-doc", + Self::Clippy => "clippy", + Self::Rustfmt => "rustfmt", + Self::RustDoc => "rust-doc", }; write!(f, "{val}") } @@ -59,10 +59,10 @@ pub enum Arch { impl Display for Arch { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let val = match self { - Arch::X86_64 => "x86_64", - Arch::Aarch64 => "aarch64", - Arch::Arm => "arm", - Arch::Wasm32 => "wasm32", + Self::X86_64 => "x86_64", + Self::Aarch64 => "aarch64", + Self::Arm => "arm", + Self::Wasm32 => "wasm32", }; write!(f, "{val}") } @@ -78,9 +78,9 @@ pub enum Vendor { impl Display for Vendor { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let val = match self { - Vendor::Unknown => "unknown", - Vendor::Apple => "apple", - Vendor::PC => "pc", + Self::Unknown => "unknown", + Self::Apple => "apple", + Self::PC => "pc", }; write!(f, "{val}") } @@ -97,10 +97,10 @@ pub enum System { impl Display for System { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let val = match self { - System::Unknown => "unknown", - System::Windows => "windows", - System::Linux => "linux", - System::Darwin => "darwin", + Self::Unknown => "unknown", + Self::Windows => "windows", + Self::Linux => "linux", + Self::Darwin => "darwin", }; write!(f, "{val}") } @@ -117,10 +117,10 @@ pub enum Abi { impl Display for Abi { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let val = match self { - Abi::Unknown => "unknown", - Abi::Gnu => "gnu", - Abi::Msvc => "msvc", - Abi::Musl => "musl", + Self::Unknown => "unknown", + Self::Gnu => "gnu", + Self::Msvc => "msvc", + Self::Musl => "musl", }; write!(f, "{val}") }