From 7e09eb921a4fdc95d82b5a7275186b060e5fb9f3 Mon Sep 17 00:00:00 2001 From: Solomon Jacobs Date: Mon, 6 Nov 2023 15:11:16 +0100 Subject: [PATCH] Reduce number of arguments for `write` --- v2/robotmk/src/section.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/v2/robotmk/src/section.rs b/v2/robotmk/src/section.rs index 4c13cd5a..0e5c5937 100644 --- a/v2/robotmk/src/section.rs +++ b/v2/robotmk/src/section.rs @@ -20,19 +20,8 @@ pub struct Section { pub content: String, } -fn write( - host: Host, - name: String, - content: &impl Serialize, - path: impl AsRef, -) -> Result<()> { +fn write(section: &Section, path: impl AsRef) -> 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(§ion).unwrap(); let mut file = NamedTempFile::new().context("Opening tempfile failed")?; file.write_all(section.as_bytes()).context(format!( @@ -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(§ion, path) } } @@ -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(§ion, path) } }