[Auto] lib/entry/link: Fix Clippy warnings

Signed-off-by: flip1995 <hello@philkrones.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
flip1995 2019-08-27 10:50:04 +02:00 committed by Matthias Beyer
parent 839f39435a
commit e2b1ed729a
3 changed files with 76 additions and 77 deletions

View file

@ -63,8 +63,7 @@ pub trait IntoValues {
impl<I: Iterator<Item = Link>> IntoValues for I { impl<I: Iterator<Item = Link>> IntoValues for I {
fn into_values(self) -> Vec<Result<Value>> { fn into_values(self) -> Vec<Result<Value>> {
self.unique() self.unique()
.sorted() .sorted() // Cannot sort toml::Value, hence uglyness here
.into_iter() // Cannot sort toml::Value, hence uglyness here
.map(|link| link.to_value().context(EM::ConversionError).map_err(Error::from)) .map(|link| link.to_value().context(EM::ConversionError).map_err(Error::from))
.collect() .collect()
} }

View file

@ -95,7 +95,7 @@ impl Linkable for Entry {
let partial : LinkPartial = self let partial : LinkPartial = self
.get_header() .get_header()
.read_partial::<LinkPartial>()? .read_partial::<LinkPartial>()?
.unwrap_or_else(|| LinkPartial::default()); .unwrap_or_else(LinkPartial::default);
partial partial
.internal .internal
@ -292,7 +292,7 @@ fn alter_linking<F>(left: &mut Entry, right: &mut Entry, f: F) -> Result<()>
debug!("Altering linkage of {:?} and {:?}", left, right); debug!("Altering linkage of {:?} and {:?}", left, right);
let get_partial = |entry: &mut Entry| -> Result<LinkPartial> { let get_partial = |entry: &mut Entry| -> Result<LinkPartial> {
Ok(entry.get_header().read_partial::<LinkPartial>()?.unwrap_or_else(|| LinkPartial::default())) Ok(entry.get_header().read_partial::<LinkPartial>()?.unwrap_or_else(LinkPartial::default))
}; };
let left_partial : LinkPartial = get_partial(left)?; let left_partial : LinkPartial = get_partial(left)?;
@ -337,7 +337,7 @@ mod test {
let links = entry.links(); let links = entry.links();
assert!(links.is_ok()); assert!(links.is_ok());
let links = links.unwrap(); let links = links.unwrap();
assert_eq!(links.collect::<Vec<_>>().len(), 0); assert_eq!(links.count(), 0);
} }
#[test] #[test]
@ -395,67 +395,67 @@ mod test {
assert!(e1.add_link(&mut e2).is_ok()); assert!(e1.add_link(&mut e2).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e1.links().unwrap().count(), 1);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e3.links().unwrap().count(), 0);
assert_eq!(e4.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e4.links().unwrap().count(), 0);
assert_eq!(e5.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e5.links().unwrap().count(), 0);
assert!(e1.add_link(&mut e3).is_ok()); assert!(e1.add_link(&mut e3).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 2); assert_eq!(e1.links().unwrap().count(), 2);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e3.links().unwrap().count(), 1);
assert_eq!(e4.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e4.links().unwrap().count(), 0);
assert_eq!(e5.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e5.links().unwrap().count(), 0);
assert!(e1.add_link(&mut e4).is_ok()); assert!(e1.add_link(&mut e4).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 3); assert_eq!(e1.links().unwrap().count(), 3);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e3.links().unwrap().count(), 1);
assert_eq!(e4.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e4.links().unwrap().count(), 1);
assert_eq!(e5.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e5.links().unwrap().count(), 0);
assert!(e1.add_link(&mut e5).is_ok()); assert!(e1.add_link(&mut e5).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 4); assert_eq!(e1.links().unwrap().count(), 4);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e3.links().unwrap().count(), 1);
assert_eq!(e4.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e4.links().unwrap().count(), 1);
assert_eq!(e5.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e5.links().unwrap().count(), 1);
assert!(e5.remove_link(&mut e1).is_ok()); assert!(e5.remove_link(&mut e1).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 3); assert_eq!(e1.links().unwrap().count(), 3);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e3.links().unwrap().count(), 1);
assert_eq!(e4.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e4.links().unwrap().count(), 1);
assert_eq!(e5.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e5.links().unwrap().count(), 0);
assert!(e4.remove_link(&mut e1).is_ok()); assert!(e4.remove_link(&mut e1).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 2); assert_eq!(e1.links().unwrap().count(), 2);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e3.links().unwrap().count(), 1);
assert_eq!(e4.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e4.links().unwrap().count(), 0);
assert_eq!(e5.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e5.links().unwrap().count(), 0);
assert!(e3.remove_link(&mut e1).is_ok()); assert!(e3.remove_link(&mut e1).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e1.links().unwrap().count(), 1);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e3.links().unwrap().count(), 0);
assert_eq!(e4.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e4.links().unwrap().count(), 0);
assert_eq!(e5.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e5.links().unwrap().count(), 0);
assert!(e2.remove_link(&mut e1).is_ok()); assert!(e2.remove_link(&mut e1).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e1.links().unwrap().count(), 0);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e2.links().unwrap().count(), 0);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e3.links().unwrap().count(), 0);
assert_eq!(e4.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e4.links().unwrap().count(), 0);
assert_eq!(e5.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e5.links().unwrap().count(), 0);
} }
@ -467,18 +467,18 @@ mod test {
let mut e1 = store.retrieve(PathBuf::from("1")).unwrap(); let mut e1 = store.retrieve(PathBuf::from("1")).unwrap();
let mut e2 = store.retrieve(PathBuf::from("2")).unwrap(); let mut e2 = store.retrieve(PathBuf::from("2")).unwrap();
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e1.links().unwrap().count(), 0);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e2.links().unwrap().count(), 0);
assert!(e1.add_link(&mut e2).is_ok()); assert!(e1.add_link(&mut e2).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e1.links().unwrap().count(), 1);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert!(e1.remove_link(&mut e2).is_ok()); assert!(e1.remove_link(&mut e2).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e1.links().unwrap().count(), 0);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e2.links().unwrap().count(), 0);
} }
#[test] #[test]
@ -490,40 +490,40 @@ mod test {
let mut e2 = store.retrieve(PathBuf::from("2")).unwrap(); let mut e2 = store.retrieve(PathBuf::from("2")).unwrap();
let mut e3 = store.retrieve(PathBuf::from("3")).unwrap(); let mut e3 = store.retrieve(PathBuf::from("3")).unwrap();
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e1.links().unwrap().count(), 0);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e2.links().unwrap().count(), 0);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e3.links().unwrap().count(), 0);
assert!(e1.add_link(&mut e2).is_ok()); // 1-2 assert!(e1.add_link(&mut e2).is_ok()); // 1-2
assert!(e1.add_link(&mut e3).is_ok()); // 1-2, 1-3 assert!(e1.add_link(&mut e3).is_ok()); // 1-2, 1-3
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 2); assert_eq!(e1.links().unwrap().count(), 2);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e3.links().unwrap().count(), 1);
assert!(e2.add_link(&mut e3).is_ok()); // 1-2, 1-3, 2-3 assert!(e2.add_link(&mut e3).is_ok()); // 1-2, 1-3, 2-3
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 2); assert_eq!(e1.links().unwrap().count(), 2);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 2); assert_eq!(e2.links().unwrap().count(), 2);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 2); assert_eq!(e3.links().unwrap().count(), 2);
assert!(e1.remove_link(&mut e2).is_ok()); // 1-3, 2-3 assert!(e1.remove_link(&mut e2).is_ok()); // 1-3, 2-3
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e1.links().unwrap().count(), 1);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 2); assert_eq!(e3.links().unwrap().count(), 2);
assert!(e1.remove_link(&mut e3).is_ok()); // 2-3 assert!(e1.remove_link(&mut e3).is_ok()); // 2-3
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e1.links().unwrap().count(), 0);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e2.links().unwrap().count(), 1);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 1); assert_eq!(e3.links().unwrap().count(), 1);
assert!(e2.remove_link(&mut e3).is_ok()); assert!(e2.remove_link(&mut e3).is_ok());
assert_eq!(e1.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e1.links().unwrap().count(), 0);
assert_eq!(e2.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e2.links().unwrap().count(), 0);
assert_eq!(e3.links().unwrap().collect::<Vec<_>>().len(), 0); assert_eq!(e3.links().unwrap().count(), 0);
} }
#[test] #[test]
@ -535,14 +535,14 @@ mod test {
let mut entry1 = store.create(PathBuf::from("test_directional_link-1")).unwrap(); let mut entry1 = store.create(PathBuf::from("test_directional_link-1")).unwrap();
let mut entry2 = store.create(PathBuf::from("test_directional_link-2")).unwrap(); let mut entry2 = store.create(PathBuf::from("test_directional_link-2")).unwrap();
assert!(entry1.unidirectional_links().unwrap().collect::<Vec<_>>().is_empty()); assert!(entry1.unidirectional_links().unwrap().next().is_none());
assert!(entry2.unidirectional_links().unwrap().collect::<Vec<_>>().is_empty()); assert!(entry2.unidirectional_links().unwrap().next().is_none());
assert!(entry1.directional_links_to().unwrap().collect::<Vec<_>>().is_empty()); assert!(entry1.directional_links_to().unwrap().next().is_none());
assert!(entry2.directional_links_to().unwrap().collect::<Vec<_>>().is_empty()); assert!(entry2.directional_links_to().unwrap().next().is_none());
assert!(entry1.directional_links_from().unwrap().collect::<Vec<_>>().is_empty()); assert!(entry1.directional_links_from().unwrap().next().is_none());
assert!(entry2.directional_links_from().unwrap().collect::<Vec<_>>().is_empty()); assert!(entry2.directional_links_from().unwrap().next().is_none());
assert!(entry1.add_link_to(&mut entry2).is_ok()); assert!(entry1.add_link_to(&mut entry2).is_ok());

View file

@ -102,9 +102,9 @@ impl StoreLinkConsistentExt for Store {
// Helper function to create a SLCECD::OneDirectionalLink error object // Helper function to create a SLCECD::OneDirectionalLink error object
let mk_one_directional_link_err = |src: StoreId, target: StoreId| -> Error { let mk_one_directional_link_err = |src: StoreId, target: StoreId| -> Error {
Error::from(format_err!("Dead link: {} -> {}", format_err!("Dead link: {} -> {}",
src.local_display_string(), src.local_display_string(),
target.local_display_string())) target.local_display_string())
}; };
// Helper lambda to check whether the _incoming_ links of each entry actually also // Helper lambda to check whether the _incoming_ links of each entry actually also