split_vec refactor
This commit is contained in:
parent
0240bf2fdf
commit
d878182c56
@ -196,16 +196,15 @@ fn parse_file(file: impl io::Read) -> Result<json::JsonValue, Box<std::error::Er
|
|||||||
Ok(ctx.data.clone())
|
Ok(ctx.data.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
// split vector to a vector of slices
|
// split slice to a vector of slices
|
||||||
#[allow(clippy::ptr_arg)]
|
fn split_vec<'a, T>(src: &'a [T], num: usize) -> Vec<&'a [T]> {
|
||||||
fn split_vec<'a, T>(src: &'a Vec<T>, num: usize) -> Vec<&'a [T]> {
|
|
||||||
let all_len = src.len();
|
let all_len = src.len();
|
||||||
let part_len = all_len / num;
|
let part_len = all_len / num;
|
||||||
let add_len = all_len % num;
|
let add_len = all_len % num;
|
||||||
let mut result = Vec::<&'a [T]>::new();
|
let mut result = Vec::<&'a [T]>::new();
|
||||||
|
|
||||||
if 1 > part_len {
|
if 0 == part_len {
|
||||||
result.push(src.as_slice());
|
result.push(src);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
for i in 0..num {
|
for i in 0..num {
|
||||||
|
Loading…
Reference in New Issue
Block a user