gdritter repos gunpowder_treason / ab1ab67
Add max output files for output func Getty Ritter 5 years ago
1 changed file(s) with 5 addition(s) and 1 deletion(s). Collapse all Expand all
11 use std::fmt::{self, Display, Formatter};
22 use std::fs::OpenOptions;
33 use std::io::{self, Write};
4
5 const MAX_OUTPUT_FILES: u32 = 500;
46
57 /// An SVG document
68 pub struct SVG {
6668 /// Print this SVG document to stdout
6769 pub fn output(self, p: &str) -> io::Result<()> {
6870 let mut file = {
69 let mut n = 0u32;
71 let mut n = 0;
7072 let mut path = format!("output/{}{:05}.svg", p, n);
7173 let mut f = OpenOptions::new().write(true).create_new(true).open(&path);
7274 loop {
7476 Ok(_) => break,
7577 Err(ref e) if e.kind() != io::ErrorKind::AlreadyExists =>
7678 return Err(io::Error::new(e.kind(), "failed to create file")),
79 _ if n > MAX_OUTPUT_FILES =>
80 return Err(io::Error::new(io::ErrorKind::Other, "Too many output files already")),
7781 _ => (),
7882 }
7983 n += 1;