Skip to content

Commit

Permalink
Reduce number of arguments for write
Browse files Browse the repository at this point in the history
  • Loading branch information
SoloJacobs committed Nov 6, 2023
1 parent dabfce7 commit cfb3538
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion v2/robotmk/src/bin/scheduler/results.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::internal_config::Suite;
use anyhow::Result;
use camino::{Utf8Path, Utf8PathBuf};
use robotmk::section::{WriteSection, WritePiggybackSection};
use robotmk::section::{WritePiggybackSection, WriteSection};
use serde::Serialize;
use std::collections::HashMap;

Expand Down
27 changes: 13 additions & 14 deletions v2/robotmk/src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,8 @@ pub struct Section {
pub content: String,
}

fn write(
host: Host,
name: String,
content: &impl Serialize,
path: impl AsRef<Utf8Path>,
) -> Result<()> {
fn write(section: &Section, path: impl AsRef<Utf8Path>) -> Result<()> {
let path = path.as_ref();
let content = serde_json::to_string(content).unwrap();
let section = Section {
name,
content,
host,
};
let section = serde_json::to_string(&section).unwrap();
let mut file = NamedTempFile::new().context("Opening tempfile failed")?;
file.write_all(section.as_bytes()).context(format!(
Expand All @@ -51,7 +40,12 @@ pub trait WriteSection {
where
Self: Serialize,
{
write(Host::Source, Self::name().into(), &self, path)
let section = Section {
name: Self::name().into(),
content: serde_json::to_string(&self).unwrap(),
host: Host::Source,
};
write(&section, path)
}
}

Expand All @@ -62,7 +56,12 @@ pub trait WritePiggybackSection {
where
Self: Serialize,
{
write(host, Self::name().into(), &self, path)
let section = Section {
name: Self::name().into(),
content: serde_json::to_string(&self).unwrap(),
host,
};
write(&section, path)
}
}

Expand Down

0 comments on commit cfb3538

Please sign in to comment.