diff options
author | James Campos <james.r.campos@gmail.com> | 2020-05-30 03:14:02 -0700 |
---|---|---|
committer | James Campos <james.r.campos@gmail.com> | 2020-05-30 03:14:02 -0700 |
commit | 2e3f4993c77b5cd986ca535d22770810701c1ad4 (patch) | |
tree | 4b8331d7527b5c4a144328126bbaadb450856eca /src | |
parent | 130e14d616bfeaedabd9b35a38e969da6bb16ab7 (diff) | |
download | bk-2e3f4993c77b5cd986ca535d22770810701c1ad4.tar.gz |
unzip
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 12 |
1 files changed, 3 insertions, 9 deletions
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)), |