Write `self.lines` to a file.
(
&self,
filename: impl AsRef<std::path::Path>,
directory: &std::path::Path,
)
| 233 | |
| 234 | /// Write `self.lines` to a file. |
| 235 | pub fn write( |
| 236 | &self, |
| 237 | filename: impl AsRef<std::path::Path>, |
| 238 | directory: &std::path::Path, |
| 239 | ) -> Result<(), error::Error> { |
| 240 | let path = directory.join(&filename); |
| 241 | eprintln!("Writing generated file: {}", path.display()); |
| 242 | let mut f = fs::File::create(path)?; |
| 243 | |
| 244 | for l in self.lines.iter().map(|l| l.as_bytes()) { |
| 245 | f.write_all(l)?; |
| 246 | } |
| 247 | |
| 248 | Ok(()) |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /// Compute the indentation of s, or None of an empty line. |