Improve readability of the code a little

This commit is contained in:
Сухарик 2016-11-25 15:42:16 +03:00 committed by Sebastian Dröge
parent eac466040e
commit 1751b5c400
3 changed files with 16 additions and 26 deletions

View file

@ -115,20 +115,18 @@ impl Adapter {
return Ok(Buffer::new());
}
if let Some(sub) = {
if let Some(front) = self.deque.front() {
if front.get_size() - self.skip >= size {
let new = front.get_buffer().copy_region(self.skip, Some(size)).unwrap();
Some(new)
} else {
None
}
let sub = self.deque.front().and_then(|front| {
if front.get_size() - self.skip >= size {
let new = front.get_buffer().copy_region(self.skip, Some(size)).unwrap();
Some(new)
} else {
None
}
} {
});
if let Some(s) = sub {
self.flush(size).unwrap();
return Ok(sub);
return Ok(s);
}
let mut new = Buffer::new_with_size(size).unwrap();

View file

@ -65,13 +65,12 @@ impl HttpSrc {
-> Result<StreamingState, ErrorMessage> {
let mut req = self.client.get(uri.clone());
if start != 0 || stop.is_some() {
req = match stop {
None => req.header(Range::Bytes(vec![ByteRangeSpec::AllFrom(start)])),
Some(stop) => {
req.header(Range::Bytes(vec![ByteRangeSpec::FromTo(start, stop - 1)]))
}
};
match (start != 0, stop) {
(false, None) => (),
(true, None) => req = req.header(Range::Bytes(vec![ByteRangeSpec::AllFrom(start)])),
(_, Some(stop)) => {
req = req.header(Range::Bytes(vec![ByteRangeSpec::FromTo(start, stop - 1)]))
}
}
let response = try!(req.send().or_else(|err| {
@ -84,11 +83,7 @@ impl HttpSrc {
["Failed to fetch {}: {}", uri, response.status()]));
}
let size = if let Some(&ContentLength(content_length)) = response.headers().get() {
Some(content_length + start)
} else {
None
};
let size = response.headers().get().map(|&ContentLength(cl)| cl + start);
let accept_byte_ranges = if let Some(&AcceptRanges(ref ranges)) = response.headers()
.get() {

View file

@ -122,10 +122,7 @@ impl SourceWrapper {
fn get_size(&self) -> u64 {
let source = &self.source.lock().unwrap();
match source.get_size() {
Some(size) => size,
None => u64::MAX,
}
source.get_size().unwrap_or(u64::MAX)
}
fn start(&self) -> bool {