Skip to content
Open
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
4 changes: 2 additions & 2 deletions crates/gh-workflow/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct Cargo {

impl Cargo {
/// Creates a new `Cargo` instance with the specified command.
pub fn new<T: ToString>(cmd: T) -> Cargo {
Cargo {
pub fn new<T: ToString>(cmd: T) -> Self {
Self {
command: cmd.to_string(),
id: Default::default(),
name: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/gh-workflow/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Volume {
pub fn new(volume_str: &str) -> Option<Self> {
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(),
})
Expand Down
32 changes: 16 additions & 16 deletions crates/gh-workflow/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum Step {

impl<A> Context<A> {
fn new() -> Self {
Context { marker: PhantomData, step: Step::Root }
Self { marker: PhantomData, step: Step::Root }
}

fn select<B>(&self, path: impl Into<String>) -> Context<B> {
Expand All @@ -56,7 +56,7 @@ impl<A> Context<A> {
}
}

pub fn eq(&self, other: Context<A>) -> Context<bool> {
pub fn eq(&self, other: Self) -> Context<bool> {
Context {
marker: Default::default(),
step: Step::Eq {
Expand All @@ -66,7 +66,7 @@ impl<A> Context<A> {
}
}

pub fn and(&self, other: Context<A>) -> Context<bool> {
pub fn and(&self, other: Self) -> Context<bool> {
Context {
marker: Default::default(),
step: Step::And {
Expand All @@ -76,7 +76,7 @@ impl<A> Context<A> {
}
}

pub fn or(&self, other: Context<A>) -> Context<bool> {
pub fn or(&self, other: Self) -> Context<bool> {
Context {
marker: Default::default(),
step: Step::Or {
Expand All @@ -88,8 +88,8 @@ impl<A> Context<A> {
}

impl Context<String> {
pub fn concat(&self, other: Context<String>) -> Context<String> {
Context {
pub fn concat(&self, other: Self) -> Self {
Self {
marker: Default::default(),
step: Step::Concat {
left: Box::new(self.step.clone()),
Expand Down Expand Up @@ -199,27 +199,27 @@ impl Context<Github> {
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}")
}
}
Expand All @@ -234,13 +234,13 @@ impl<A> fmt::Display for Context<A> {

impl<A> From<Context<A>> for Expression {
fn from(value: Context<A>) -> Self {
Expression::new(value.to_string())
Self::new(value.to_string())
}
}

impl<T: Into<String>> From<T> for Context<String> {
fn from(value: T) -> Self {
Context {
Self {
marker: Default::default(),
step: Step::Literal(value.into()),
}
Expand Down
8 changes: 4 additions & 4 deletions crates/gh-workflow/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Env(pub IndexMap<String, Value>);
impl From<IndexMap<String, Value>> for Env {
/// Converts an `IndexMap` into an `Env`.
fn from(value: IndexMap<String, Value>) -> Self {
Env(value)
Self(value)
}
}

Expand All @@ -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<K: ToString, V: Into<Value>>(key: K, value: V) -> Self {
Env::default().add(key, value)
Self::default().add(key, value)
}

/// Adds an environment variable to the `Env`.
Expand All @@ -48,6 +48,6 @@ impl<S1: Display, S2: Display> From<(S1, S2)> for Env {
fn from(value: (S1, S2)) -> Self {
let mut index_map: IndexMap<String, Value> = IndexMap::new();
index_map.insert(value.0.to_string(), Value::String(value.1.to_string()));
Env(index_map)
Self(index_map)
}
}
2 changes: 1 addition & 1 deletion crates/gh-workflow/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
{
/// Converts a value into a `RunsOn` instance.
fn from(value: T) -> Self {
RunsOn(value.into())
Self(value.into())
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/gh-workflow/src/release_plz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
}
Expand All @@ -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"),
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions crates/gh-workflow/src/rust_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,47 @@ 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<S: ToString>(name: S) -> Self {
RustFlags::Lint(name.to_string(), Lint::Allow)
Self::Lint(name.to_string(), Lint::Allow)
}

pub fn warn<S: ToString>(name: S) -> Self {
RustFlags::Lint(name.to_string(), Lint::Warn)
Self::Lint(name.to_string(), Lint::Warn)
}

pub fn deny<S: ToString>(name: S) -> Self {
RustFlags::Lint(name.to_string(), Lint::Deny)
Self::Lint(name.to_string(), Lint::Deny)
}

pub fn forbid<S: ToString>(name: S) -> Self {
RustFlags::Lint(name.to_string(), Lint::Forbid)
Self::Lint(name.to_string(), Lint::Forbid)
}

pub fn codegen<S: ToString>(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}"),
Lint::Forbid => write!(f, "-F{name}"),
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}"),
}
}
}
Expand All @@ -72,6 +72,6 @@ impl From<RustFlags> 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)
}
}
16 changes: 8 additions & 8 deletions crates/gh-workflow/src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct Input(#[serde(skip_serializing_if = "IndexMap::is_empty")] pub IndexM
impl From<IndexMap<String, Value>> for Input {
/// Converts an `IndexMap` into an `Input`.
fn from(value: IndexMap<String, Value>) -> Self {
Input(value)
Self(value)
}
}

Expand Down Expand Up @@ -162,7 +162,7 @@ pub struct StepValue {
impl StepValue {
/// Creates a new `StepValue` that runs the provided shell command.
pub fn run<T: ToString>(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.
Expand All @@ -171,7 +171,7 @@ impl StepValue {
repo: Repo,
version: Version,
) -> Self {
StepValue {
Self {
uses: Some(format!(
"{}/{}@{}",
owner.to_string(),
Expand All @@ -197,7 +197,7 @@ impl<T> Step<T> {

impl Step<()> {
pub fn new(name: impl ToString) -> Self {
Step {
Self {
value: StepValue::default().name(name.to_string()),
marker: Default::default(),
}
Expand All @@ -222,7 +222,7 @@ impl Step<()> {
/// Represents a step that uses an action.
impl Step<Use> {
/// Creates a step pointing to the default GitHub's Checkout Action.
pub fn checkout() -> Step<Use> {
pub fn checkout() -> Self {
Step::new("Checkout Code").uses("actions", "checkout", "v5")
}

Expand All @@ -246,13 +246,13 @@ impl<S1: ToString, S2: ToString> From<(S1, S2)> for Input {
fn from(value: (S1, S2)) -> Self {
let mut index_map: IndexMap<String, Value> = IndexMap::new();
index_map.insert(value.0.to_string(), Value::String(value.1.to_string()));
Input(index_map)
Self(index_map)
}
}

impl Step<Toolchain> {
pub fn toolchain() -> Step<Toolchain> {
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 {
Expand Down
Loading
Loading