difftreelog
fix do not write trailing newline in --multi for -S
in: master
2 files changed
cmds/jrsonnet/src/main.rsdiffbeforeafterboth200 }200 }201 println!("{}", path.to_str().expect("path"));201 println!("{}", path.to_str().expect("path"));202 let mut file = File::create(path)?;202 let mut file = File::create(path)?;203 writeln!(203 write!(204 file,204 file,205 "{}",205 "{}",206 data.manifest(&manifest_format)206 data.manifest(&manifest_format)207 .with_description(|| format!("manifesting {field}"))?207 .with_description(|| format!("manifesting {field}"))?,208 )?;208 )?;209 if manifest_format.file_trailing_newline() {210 writeln!(file)?;211 }212 file.flush()?;209 }213 }210 } else if let Some(path) = opts.output.output_file {214 } else if let Some(path) = opts.output.output_file {211 if opts.output.create_output_dirs {215 if opts.output.create_output_dirs {crates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth12 self.manifest_buf(val, &mut out)?;12 self.manifest_buf(val, &mut out)?;13 Ok(out)13 Ok(out)14 }14 }15 /// When outputing to file, is it safe to append a trailing newline (I.e newline won't change16 /// the meaning).17 ///18 /// Default implementation returns `true`19 fn file_trailing_newline(&self) -> bool {20 true21 }15}22}16impl<T> ManifestFormat for Box<T>23impl<T> ManifestFormat for Box<T>17where24where21 let inner = &**self;28 let inner = &**self;22 inner.manifest_buf(val, buf)29 inner.manifest_buf(val, buf)23 }30 }31 fn file_trailing_newline(&self) -> bool {32 let inner = &**self;33 inner.file_trailing_newline()34 }24}35}25impl<T> ManifestFormat for &'_ T36impl<T> ManifestFormat for &'_ T26where37where30 let inner = &**self;41 let inner = &**self;31 inner.manifest_buf(val, buf)42 inner.manifest_buf(val, buf)32 }43 }44 fn file_trailing_newline(&self) -> bool {45 let inner = &**self;46 inner.file_trailing_newline()47 }33}48}344935#[derive(PartialEq, Eq, Clone, Copy)]50#[derive(PartialEq, Eq, Clone, Copy)]253 fn manifest_buf(&self, val: Val, out: &mut String) -> Result<()> {268 fn manifest_buf(&self, val: Val, out: &mut String) -> Result<()> {254 JsonFormat::std_to_string().manifest_buf(val, out)269 JsonFormat::std_to_string().manifest_buf(val, out)255 }270 }271 fn file_trailing_newline(&self) -> bool {272 false273 }256}274}257pub struct StringFormat;275pub struct StringFormat;258impl ManifestFormat for StringFormat {276impl ManifestFormat for StringFormat {263 write!(out, "{s}").unwrap();281 write!(out, "{s}").unwrap();264 Ok(())282 Ok(())265 }283 }284 fn file_trailing_newline(&self) -> bool {285 false286 }266}287}267288268pub struct YamlStreamFormat<I>(pub I);289pub struct YamlStreamFormat<I>(pub I);