diff --git a/lib/dubp/wot/lib.rs b/lib/dubp/wot/lib.rs index d092b6a3a0741892ca54cf9dea379f58ee88c338..927c7a3f61a182586f48c1aa3b0fb3a8aabc8843 100644 --- a/lib/dubp/wot/lib.rs +++ b/lib/dubp/wot/lib.rs @@ -27,6 +27,8 @@ //! [js-tests]: https://github.com/duniter/wot/blob/master/wotcpp/webOfTrust.cpp #![deny( + clippy::option_unwrap_used, + clippy::result_unwrap_used, missing_docs, missing_debug_implementations, missing_copy_implementations, diff --git a/lib/dubp/wot/operations/centrality.rs b/lib/dubp/wot/operations/centrality.rs index f1225e1163649060cb5b36fc71205c8642eb9643..029d8927a4d00bf0bee1ca8c610f1d8bc231b9e5 100644 --- a/lib/dubp/wot/operations/centrality.rs +++ b/lib/dubp/wot/operations/centrality.rs @@ -50,8 +50,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat sigma[s.0] = 1.0; d[s.0] = 0; q.push_back(s); - while !q.is_empty() { - let v = q.pop_front().unwrap(); + while let Some(v) = q.pop_front() { stack.push(v); for w in wot.get_links_source(v).expect("v don't have any source !") { // w found for the first time ? @@ -68,8 +67,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat } let mut delta = vec![0.0; wot_size]; // stack returns vertices in order of non-increasing distance from s - while !stack.is_empty() { - let w = stack.pop().unwrap(); + while let Some(w) = stack.pop() { if paths.contains_key(&w) { for v in paths.get(&w).expect("Not found w in p !") { if enabled_nodes.contains(&w) { @@ -103,8 +101,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat sigma[s.0] = 1.0; d[s.0] = 0; q.push_back(s); - while !q.is_empty() { - let v = q.pop_front().unwrap(); + while let Some(v) = q.pop_front() { stack.push(v); for w in wot.get_links_source(v).expect("v don't have any source !") { // w found for the first time ? @@ -121,8 +118,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat } let mut delta = vec![0.0; wot_size]; // stack returns vertices in order of non-increasing distance from s - while !stack.is_empty() { - let w = stack.pop().unwrap(); + while let Some(w) = stack.pop() { if paths.contains_key(&w) { for v in paths.get(&w).expect("Not found w in p !") { if enabled_nodes.contains(&w) { @@ -156,8 +152,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat sigma[s.0] = 1.0; d[s.0] = 0; q.push_back(s); - while !q.is_empty() { - let v = q.pop_front().unwrap(); + while let Some(v) = q.pop_front() { stack.push(v); if d[v.0] < step_max as isize { for w in wot.get_links_source(v).expect("v don't have any source !") { @@ -176,8 +171,7 @@ impl<T: WebOfTrust> CentralitiesCalculator<T> for UlrikBrandesCentralityCalculat } let mut delta = vec![0.0; wot_size]; // stack returns vertices in order of non-increasing distance from s - while !stack.is_empty() { - let w = stack.pop().unwrap(); + while let Some(w) = stack.pop() { if paths.contains_key(&w) { for v in paths.get(&w).expect("Not found w in p !") { if enabled_nodes.contains(&w) { diff --git a/lib/dubp/wot/operations/distance.rs b/lib/dubp/wot/operations/distance.rs index 5c6ccb5fc800b855452c6a1299d45c80f05f5658..53d77f43cc7ee041b74ed41164bf6ed5a37ef93a 100644 --- a/lib/dubp/wot/operations/distance.rs +++ b/lib/dubp/wot/operations/distance.rs @@ -97,7 +97,7 @@ impl<T: WebOfTrust + Sync> DistanceCalculator<T> for RustyDistanceCalculator { .par_iter() .map(|&id| { wot.get_links_source(id) - .unwrap() + .expect("get_links_source must return a value") .iter() .filter(|source| !area.contains(source)) .cloned() @@ -116,7 +116,10 @@ impl<T: WebOfTrust + Sync> DistanceCalculator<T> for RustyDistanceCalculator { let mut success = area.iter().filter(|n| sentries.contains(n)).count() as u32; let success_at_border = border.iter().filter(|n| sentries.contains(n)).count() as u32; let mut sentries = sentries.len() as u32; - if wot.is_sentry(node, sentry_requirement as usize).unwrap() { + if wot + .is_sentry(node, sentry_requirement as usize) + .expect("is_sentry must return a value") + { sentries -= 1; success -= 1; } diff --git a/lib/dubp/wot/operations/path.rs b/lib/dubp/wot/operations/path.rs index 4304e1822284bfc5fadb8782ba54da9a3f2ce9b2..5ca9b70283c86827ea6da7b1699ec2fa8fb8db85 100644 --- a/lib/dubp/wot/operations/path.rs +++ b/lib/dubp/wot/operations/path.rs @@ -52,7 +52,10 @@ impl<T: WebOfTrust> PathFinder<T> for RustyPathFinder { let mut next_border = HashSet::new(); for node in border { - for source in &wot.get_links_source(node).unwrap() { + for source in &wot + .get_links_source(node) + .expect("links source must not be None") + { match graph[source.0].0 { path_distance if path_distance > distance => { // shorter path, we replace @@ -80,7 +83,7 @@ impl<T: WebOfTrust> PathFinder<T> for RustyPathFinder { let mut new_paths = vec![]; for path in &paths { - let node = path.last().unwrap(); + let node = path.last().expect("path should not be empty"); if node == &to { // If path is complete, we keep it.