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 47c013e commit 7e09eb9
Showing 1 changed file with 13 additions and 14 deletions.
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 7e09eb9

Please sign in to comment.