clean up save_to_disk by cloning OutputData

This commit is contained in:
132nd-Professor
2022-11-07 17:35:06 +01:00
parent 61cfbd3e13
commit a6acdbac4f
+19 -14
View File
@@ -98,6 +98,7 @@ where
} }
} }
#[derive(Clone)]
pub struct OutputData { pub struct OutputData {
input_filename: Arc<String>, input_filename: Arc<String>,
is_zip: bool, is_zip: bool,
@@ -137,24 +138,28 @@ impl OutputData {
let handles: Vec<_> = coalitions let handles: Vec<_> = coalitions
.iter() .iter()
.map(|coalition| { .map(|coalition| {
let z = self.is_zip; let thread_self = self.clone();
let b = self.body.clone(); let thread_coalition = coalition.clone();
let cpl = self.coalition_per_line.clone();
let c = coalition.clone();
let h = self.header.clone();
let i = self.input_filename.clone();
thread::spawn(move || { thread::spawn(move || {
let mut writer = create_writer(z, &i.clone(), &c) let mut writer = create_writer(
.with_context(|| format!("could not create writer for {c}")) thread_self.is_zip,
&thread_self.input_filename,
&thread_coalition,
)
.with_context(|| format!("could not create writer for {thread_coalition}"))
.unwrap();
writer
.write_strings(&thread_self.header)
.with_context(|| format!("could not write header for {thread_coalition}"))
.unwrap(); .unwrap();
writer writer
.write_strings(&h) .write_for_coalition(
.with_context(|| format!("could not write header for {c}")) &thread_self.body,
.unwrap(); &thread_self.coalition_per_line,
writer &thread_coalition,
.write_for_coalition(&b, &cpl, &c) )
.with_context(|| format!("could not write body for {c}")) .with_context(|| format!("could not write body for {thread_coalition}"))
.unwrap(); .unwrap();
}) })
}) })