From d878182c569e3cb071f59a740d8d7656602ce81c Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 26 Jul 2019 23:19:13 +0300 Subject: [PATCH] split_vec refactor --- src/main.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0034cbd..57f19db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -196,16 +196,15 @@ fn parse_file(file: impl io::Read) -> Result(src: &'a Vec, num: usize) -> Vec<&'a [T]> { +// split slice to a vector of slices +fn split_vec<'a, T>(src: &'a [T], num: usize) -> Vec<&'a [T]> { let all_len = src.len(); let part_len = all_len / num; let add_len = all_len % num; let mut result = Vec::<&'a [T]>::new(); - if 1 > part_len { - result.push(src.as_slice()); + if 0 == part_len { + result.push(src); return result; } for i in 0..num {