lints
This commit is contained in:
+23
-9
@@ -1,4 +1,3 @@
|
||||
|
||||
#[derive(PartialEq, Debug, Clone, Copy)]
|
||||
struct Range {
|
||||
// todo: consider just using a map instead
|
||||
@@ -12,7 +11,7 @@ enum RangeLocation {
|
||||
LeftEnd,
|
||||
RightEnd,
|
||||
Middle,
|
||||
No
|
||||
No,
|
||||
}
|
||||
|
||||
impl Range {
|
||||
@@ -25,7 +24,7 @@ impl Range {
|
||||
return RangeLocation::LeftEnd;
|
||||
}
|
||||
if index >= self.end {
|
||||
return RangeLocation::No
|
||||
return RangeLocation::No;
|
||||
}
|
||||
if index == self.end - 1 {
|
||||
return RangeLocation::RightEnd;
|
||||
@@ -44,14 +43,24 @@ pub struct Blob {
|
||||
}
|
||||
|
||||
impl Blob {
|
||||
pub fn new() -> Self { Self {bytes: Vec::new(), valid_ranges: Vec::new()} }
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
bytes: Vec::new(),
|
||||
valid_ranges: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn append(&mut self, input: &[u8]) {
|
||||
let new_range = Range {start: self.bytes.len(), end: self.bytes.len() + input.len()};
|
||||
let new_range = Range {
|
||||
start: self.bytes.len(),
|
||||
end: self.bytes.len() + input.len(),
|
||||
};
|
||||
|
||||
// we are appending so only have to check the last range
|
||||
match self.valid_ranges.last_mut() {
|
||||
Some(range) if range.where_in_range(new_range.start) != RangeLocation::No => range.end = new_range.end,
|
||||
Some(range) if range.where_in_range(new_range.start) != RangeLocation::No => {
|
||||
range.end = new_range.end
|
||||
}
|
||||
_ => self.valid_ranges.push(new_range),
|
||||
}
|
||||
self.bytes.extend_from_slice(input);
|
||||
@@ -64,9 +73,12 @@ impl Blob {
|
||||
slice.swap_with_slice(output);
|
||||
|
||||
// we copy existing entries into a new list to avoid iterator invalidation
|
||||
// of inserting while iterating
|
||||
// from inserting while iterating
|
||||
// todo: might be a better way
|
||||
let clear_range = Range{ start, end: start + len };
|
||||
let clear_range = Range {
|
||||
start,
|
||||
end: start + len,
|
||||
};
|
||||
let mut new_ranges = Vec::new();
|
||||
let mut i = 0;
|
||||
while i < self.valid_ranges.len() {
|
||||
@@ -86,7 +98,9 @@ impl Blob {
|
||||
new_ranges.push(range);
|
||||
}
|
||||
|
||||
if let Some(er) = extra_range && !er.is_empty() {
|
||||
if let Some(er) = extra_range
|
||||
&& !er.is_empty()
|
||||
{
|
||||
new_ranges.push(er);
|
||||
}
|
||||
i += 1;
|
||||
|
||||
Reference in New Issue
Block a user