From 01ba96b914cab82e7f72cc099428f58e8918b16e Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:18:11 +0900 Subject: [PATCH] :memo: Enhance documentation comments for `Archive` --- lib/src/archive/write.rs | 62 ++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/lib/src/archive/write.rs b/lib/src/archive/write.rs index 066569d1..719cc6c5 100644 --- a/lib/src/archive/write.rs +++ b/lib/src/archive/write.rs @@ -132,25 +132,25 @@ impl Archive { /// # Examples /// /// ```no_run - /// use libpna::{Archive, EntryBuilder, EntryPart, WriteOption}; - /// use std::fs::File; - /// use std::io; + /// # use libpna::{Archive, EntryBuilder, EntryPart, WriteOption}; + /// # use std::fs::File; + /// # use std::io; /// - /// fn main() -> io::Result<()> { - /// let part1_file = File::create("example.part1.pna")?; - /// let mut archive_part1 = Archive::write_header(part1_file)?; - /// let entry = EntryBuilder::new_file( - /// "example.txt".try_into().unwrap(), - /// WriteOption::builder().build(), - /// )? - /// .build()?; - /// archive_part1.add_entry_part(EntryPart::from(entry))?; - /// - /// let part2_file = File::create("example.part2.pna")?; - /// let archive_part2 = archive_part1.split_to_next_archive(part2_file)?; - /// archive_part2.finalize()?; - /// Ok(()) - /// } + /// # fn main() -> io::Result<()> { + /// let part1_file = File::create("example.part1.pna")?; + /// let mut archive_part1 = Archive::write_header(part1_file)?; + /// let entry = EntryBuilder::new_file( + /// "example.txt".try_into().unwrap(), + /// WriteOption::builder().build(), + /// )? + /// .build()?; + /// archive_part1.add_entry_part(EntryPart::from(entry))?; + /// + /// let part2_file = File::create("example.part2.pna")?; + /// let archive_part2 = archive_part1.split_to_next_archive(part2_file)?; + /// archive_part2.finalize()?; + /// # Ok(()) + /// # } /// ``` pub fn add_entry_part(&mut self, entry_part: EntryPart) -> io::Result { let mut chunk_writer = ChunkWriter::from(&mut self.inner); @@ -166,6 +166,30 @@ impl Archive { chunk_writer.write_chunk((ChunkType::ANXT, [].as_slice())) } + /// Split to the next archive. + /// + /// # Examples + /// ```no_run + /// # use libpna::{Archive, EntryBuilder, EntryPart, WriteOption}; + /// # use std::fs::File; + /// # use std::io; + /// + /// # fn main() -> io::Result<()> { + /// let part1_file = File::create("example.part1.pna")?; + /// let mut archive_part1 = Archive::write_header(part1_file)?; + /// let entry = EntryBuilder::new_file( + /// "example.txt".try_into().unwrap(), + /// WriteOption::builder().build(), + /// )? + /// .build()?; + /// archive_part1.add_entry_part(EntryPart::from(entry))?; + /// + /// let part2_file = File::create("example.part2.pna")?; + /// let archive_part2 = archive_part1.split_to_next_archive(part2_file)?; + /// archive_part2.finalize()?; + /// # Ok(()) + /// # } + /// ``` pub fn split_to_next_archive(mut self, writer: OW) -> io::Result> { let next_archive_number = self.header.archive_number + 1; let header = ArchiveHeader::new(0, 0, next_archive_number); @@ -191,7 +215,7 @@ impl Archive { /// let file = File::create("foo.pna")?; /// let mut archive = Archive::write_header(file)?; /// archive.finalize()?; - /// Ok(()) + /// # Ok(()) /// # } /// ``` pub fn finalize(mut self) -> io::Result {