From 2e3f4993c77b5cd986ca535d22770810701c1ad4 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 30 May 2020 03:14:02 -0700 Subject: unzip --- src/main.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 0d68a05..c66bf64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -352,8 +352,8 @@ impl Bk<'_> { fn new(epub: epub::Epub, chapter: usize, line: usize, max_width: u16) -> Self { let (cols, rows) = terminal::size().unwrap(); let width = min(cols, max_width) as usize; - let mut chapters = Vec::with_capacity(epub.chapters.len()); + for (title, text) in epub.chapters { let title = if title.chars().count() > width { title @@ -364,14 +364,7 @@ impl Bk<'_> { } else { title }; - let wrap = wrap(&text, width); - let mut lines = Vec::with_capacity(wrap.len()); - let mut bytes = Vec::with_capacity(wrap.len()); - - for (byte, line) in wrap { - lines.push(line); - bytes.push(byte); - } + let (bytes, lines) = wrap(&text, width).into_iter().unzip(); chapters.push(Chapter { title, text, @@ -535,6 +528,7 @@ fn restore(save_path: &str) -> Option<(String, usize, usize)> { .to_string() }; + // XXX move errors when i try to refactor match (save, path) { (Err(_), None) => None, (Err(_), Some(path)) => Some((canon(path), 0, 0)), -- cgit v1.2.3