Struct clog::LogWriter
[−]
[src]
pub struct LogWriter<'a, 'cc> { // some fields omitted }
Writes commits to a specified Write
object
Methods
impl<'a, 'cc> LogWriter<'a, 'cc>
fn new<T>(writer: &'a mut T, options: &'cc Clog) -> LogWriter<'a, 'cc> where T: Write + Send
Creates a new instance of the LogWriter using a Write
object and a Clog
object as the
configuration options to use while writing.
Example
let clog = Clog::new().unwrap_or_else(|e| { println!("Error initializing: {}", e); std::process::exit(1); }); // Open and prepend, or create the changelog file... let mut contents = String::new(); File::open(&Path::new(&clog.changelog[..])).map(|mut f| f.read_to_string(&mut contents).ok()).ok(); let mut file = File::create(&Path::new(&clog.changelog[..])).ok().unwrap(); // Create the LogWriter... let mut writer = LogWriter::new(&mut file, &clog);
fn write_header(&mut self) -> Result<()>
Writes the initial header inforamtion for a release
Example
let clog = Clog::new().unwrap_or_else(|e| { println!("Error initializing: {}", e); std::process::exit(1); }); // Get the commits we're interested in... let sm = SectionMap::from_commits(clog.get_commits()); // Open and prepend, or create the changelog file... let mut contents = String::new(); File::open(&Path::new(&clog.changelog[..])).map(|mut f| f.read_to_string(&mut contents).ok()).ok(); let mut file = File::create(&Path::new(&clog.changelog[..])).ok().unwrap(); // Write the header... let mut writer = LogWriter::new(&mut file, &clog); writer.write_header().ok().expect("failed to write header");
fn write_section(&mut self, title: &str, section: &BTreeMap<&String, &Vec<Commit>>) -> Result<()>
Writes a particular section of a changelog
Example
let clog = Clog::new().unwrap_or_else(|e| { println!("Error initializing: {}", e); std::process::exit(1); }); // Get the commits we're interested in... let sm = SectionMap::from_commits(clog.get_commits()); // Open and prepend, or create the changelog file... let mut contents = String::new(); File::open(&Path::new(&clog.changelog[..])).map(|mut f| f.read_to_string(&mut contents).ok()).ok(); let mut file = File::create(&Path::new(&clog.changelog[..])).ok().unwrap(); // Write the header... let mut writer = LogWriter::new(&mut file, &clog); writer.write_header().ok().expect("failed to write header"); // Write the sections for (sec, secmap) in sm.sections { writer.write_section(&sec[..], &secmap.iter().collect::<BTreeMap<_,_>>()).ok().expect(&format!("failed to write {}", sec)[..]); } writer.write(&contents[..]).ok().expect("failed to write contents");
fn write(&mut self, content: &str) -> Result<()>
Writes some contents to the Write
writer object