Skip to content

Commit

Permalink
fix: simplify From for RunsOn
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Nov 9, 2024
1 parent b78800c commit 477a6de
Showing 1 changed file with 7 additions and 36 deletions.
43 changes: 7 additions & 36 deletions workspace/gh-workflow/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,13 @@ pub enum ActivityType {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Default)]
#[serde(transparent)]
pub struct RunsOn(Value);
impl From<Value> for RunsOn {
fn from(value: Value) -> Self {
RunsOn(value)

impl<T> From<T> for RunsOn
where
T: Into<Value>,
{
fn from(value: T) -> Self {
RunsOn(value.into())
}
}

Expand Down Expand Up @@ -221,39 +225,6 @@ impl Job {
}
}

impl From<&str> for RunsOn {
fn from(value: &str) -> Self {
RunsOn(Value::String(value.to_string()))
}
}

impl From<Vec<&str>> for RunsOn {
fn from(value: Vec<&str>) -> Self {
RunsOn(Value::Array(
value
.into_iter()
.map(|v| v.to_string())
.map(Value::String)
.collect(),
))
}
}

impl<V> From<Vec<(&str, V)>> for RunsOn
where
V: Into<RunsOn>,
{
fn from(value: Vec<(&str, V)>) -> Self {
let val = value.into_iter().map(|(a, b)| (a.to_string(), b.into()));
let mut map = Map::new();
for (k, v) in val {
map.insert(k.to_string(), v.0);
}

RunsOn(Value::Object(map))
}
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum StepValue {
Expand Down

0 comments on commit 477a6de

Please sign in to comment.