chore: cargo fmt

This commit is contained in:
Joonas Koivunen 2020-06-05 15:15:40 +03:00
parent 98df68a03a
commit 9fc620276a
3 changed files with 32 additions and 39 deletions

View File

@ -64,10 +64,7 @@ impl Into<String> for File {
use crate::{Ipfs, IpfsTypes};
use async_stream::stream;
use futures::stream::Stream;
use ipfs_unixfs::file::{
visit::IdleFileVisit,
FileReadFailed,
};
use ipfs_unixfs::file::{visit::IdleFileVisit, FileReadFailed};
use std::fmt;
use std::ops::Range;

View File

@ -229,11 +229,10 @@ mod tests {
#[test]
fn visiting_just_content() {
let res = IdleFileVisit::default()
.start(CONTENT_FILE);
let res = IdleFileVisit::default().start(CONTENT_FILE);
match res {
Ok((b"content", _, None)) => {},
Ok((b"content", _, None)) => {}
x => unreachable!("unexpected {:?}", x),
}
}
@ -245,7 +244,7 @@ mod tests {
.start(CONTENT_FILE);
match res {
Ok((b"", _, None)) => {},
Ok((b"", _, None)) => {}
x => unreachable!("unexpected {:?}", x),
}
}
@ -288,7 +287,7 @@ mod tests {
let cid = Cid::new_v0(mh).unwrap();
match self.blocks.insert(cid.clone(), block.to_vec()) {
None => {},
None => {}
_ => unreachable!("duplicate cid {}", cid),
}
@ -342,10 +341,11 @@ mod tests {
let root = FileReader::from_block(blocks.get_by_str(target)).unwrap();
let (mut links_and_ranges, traversal) = match root.content() {
(FileContent::Spread(iter), traversal) => {
(iter.map(|(link, range)| (link.Hash.unwrap_borrowed().to_vec(), range))
.collect::<Vec<(Vec<u8>, _)>>(), traversal)
}
(FileContent::Spread(iter), traversal) => (
iter.map(|(link, range)| (link.Hash.unwrap_borrowed().to_vec(), range))
.collect::<Vec<(Vec<u8>, _)>>(),
traversal,
),
x => unreachable!("unexpected {:?}", x),
};
@ -380,7 +380,7 @@ mod tests {
Ok((content, _, step)) => {
ret.extend(content);
step
},
}
x => unreachable!("{:?}", x),
};
@ -392,7 +392,7 @@ mod tests {
Ok((content, next_step)) => {
ret.extend(content);
step = next_step;
},
}
x => unreachable!("{:?}", x),
}
}
@ -415,8 +415,7 @@ mod tests {
let blocks = FakeBlockstore::with_fixtures();
let start = "QmRJHYTNvC3hmd9gJQARxLR1QMEincccBV53bBw524yyq6";
let visit = IdleFileVisit::default()
.with_target_range(1..6);
let visit = IdleFileVisit::default().with_target_range(1..6);
let bytes = collect_bytes(&blocks, visit, start);
assert_eq!(&bytes[..], b"oobar");
@ -427,8 +426,7 @@ mod tests {
let blocks = FakeBlockstore::with_fixtures();
let start = "QmRJHYTNvC3hmd9gJQARxLR1QMEincccBV53bBw524yyq6";
let visit = IdleFileVisit::default()
.with_target_range(0..1);
let visit = IdleFileVisit::default().with_target_range(0..1);
let bytes = collect_bytes(&blocks, visit, start);
assert_eq!(&bytes[..], b"f");
@ -439,8 +437,7 @@ mod tests {
let blocks = FakeBlockstore::with_fixtures();
let start = "QmRJHYTNvC3hmd9gJQARxLR1QMEincccBV53bBw524yyq6";
let visit = IdleFileVisit::default()
.with_target_range(7..20);
let visit = IdleFileVisit::default().with_target_range(7..20);
let bytes = collect_bytes(&blocks, visit, start);
assert_eq!(&bytes[..], b"");

View File

@ -17,9 +17,7 @@ pub struct IdleFileVisit {
impl IdleFileVisit {
/// Target range represents the target byte range of the file we are interested in visiting.
pub fn with_target_range(self, range: Range<u64>) -> Self {
Self {
range: Some(range),
}
Self { range: Some(range) }
}
/// Begins the visitation by offering the first block to be visited.
@ -190,7 +188,11 @@ fn block_is_in_target_range(block: &Range<u64>, target: Option<&Range<u64>>) ->
/// Whenever we propagate the content from the tree upwards, we need to make sure it's inside the
/// range we were originally interested in.
fn maybe_target_slice<'a>(content: &'a [u8], block: &Range<u64>, target: Option<&Range<u64>>) -> &'a [u8] {
fn maybe_target_slice<'a>(
content: &'a [u8],
block: &Range<u64>,
target: Option<&Range<u64>>,
) -> &'a [u8] {
if let Some(target) = target {
target_slice(content, block, target)
} else {
@ -240,32 +242,25 @@ mod tests {
let cases: &[(&[u8], u64, Range<u64>, &[u8])] = &[
// xxxx xxxx cont ent_
// ^^^^ ^^^^
(b"content_", 8, 0..8, b""),
(b"content_", 8, 0..8, b""),
// xxxx xxxx cont ent_
// ^^^^ ^^^^ ^
(b"content_", 8, 0..9, b"c"),
(b"content_", 8, 0..9, b"c"),
// xxxx xxxx cont ent_
// ^^^ ^^^^ ^^^^ ^^^^ ...
(b"content_", 8, 1..20, b"content_"),
(b"content_", 8, 1..20, b"content_"),
// xxxx xxxx cont ent_
// ^ ^^^^ ^^^^ ...
(b"content_", 8, 7..20, b"content_"),
(b"content_", 8, 7..20, b"content_"),
// xxxx xxxx cont ent_
// ^^^^ ^^^^ ...
(b"content_", 8, 8..20, b"content_"),
(b"content_", 8, 8..20, b"content_"),
// xxxx xxxx cont ent_
// ^^^ ^^^^ ...
(b"content_", 8, 9..20, b"ontent_"),
(b"content_", 8, 9..20, b"ontent_"),
// xxxx xxxx cont ent_
// ^ ...
(b"content_", 8, 15..20, b"_"),
// xxxx xxxx cont ent_ yyyy
// ^^^^
(b"content_", 8, 16..20, b""),
@ -274,7 +269,11 @@ mod tests {
for (block_data, block_offset, target_range, expected) in cases {
let block_range = *block_offset..(block_offset + block_data.len() as u64);
let sliced = target_slice(block_data, &block_range, target_range);
assert_eq!(sliced, *expected, "slice {:?} of block {:?}", target_range, block_range);
assert_eq!(
sliced, *expected,
"slice {:?} of block {:?}",
target_range, block_range
);
}
}
}