summaryrefslogtreecommitdiff
path: root/src/rust/protover/protoset.rs
diff options
context:
space:
mode:
authorcypherpunks <cypherpunks@torproject.org>2018-08-03 19:48:10 +0000
committerNick Mathewson <nickm@torproject.org>2018-08-16 08:42:57 -0400
commit6b609ce4356423a28e7b421a9f09849d831a0c6f (patch)
tree0feff6aae6ea11f4933d47e96949539c32368e3d /src/rust/protover/protoset.rs
parent32ad8e991999277948e896196731f2919c390f00 (diff)
downloadtor-6b609ce4356423a28e7b421a9f09849d831a0c6f.tar.gz
tor-6b609ce4356423a28e7b421a9f09849d831a0c6f.zip
rust: run rustfmt
Diffstat (limited to 'src/rust/protover/protoset.rs')
-rw-r--r--src/rust/protover/protoset.rs62
1 files changed, 40 insertions, 22 deletions
diff --git a/src/rust/protover/protoset.rs b/src/rust/protover/protoset.rs
index 4afc50edf8..5cea03983a 100644
--- a/src/rust/protover/protoset.rs
+++ b/src/rust/protover/protoset.rs
@@ -53,7 +53,7 @@ impl Default for ProtoSet {
fn default() -> Self {
let pairs: Vec<(Version, Version)> = Vec::new();
- ProtoSet{ pairs }
+ ProtoSet { pairs }
}
}
@@ -73,7 +73,7 @@ impl<'a> ProtoSet {
pairs.sort_unstable();
pairs.dedup();
- ProtoSet{ pairs }.is_ok()
+ ProtoSet { pairs }.is_ok()
}
}
@@ -263,7 +263,8 @@ impl ProtoSet {
/// ```
// XXX we could probably do something more efficient here. —isis
pub fn retain<F>(&mut self, f: F)
- where F: FnMut(&Version) -> bool
+ where
+ F: FnMut(&Version) -> bool,
{
let mut expanded: Vec<Version> = self.clone().expand();
expanded.retain(f);
@@ -299,7 +300,7 @@ impl FromStr for ProtoSet {
/// * there are greater than 2^16 version numbers to expand.
///
/// # Examples
- ///
+ ///
/// ```
/// use std::str::FromStr;
///
@@ -350,10 +351,10 @@ impl FromStr for ProtoSet {
} else if p.contains('-') {
let mut pair = p.split('-');
- let low = pair.next().ok_or(ProtoverError::Unparseable)?;
+ let low = pair.next().ok_or(ProtoverError::Unparseable)?;
let high = pair.next().ok_or(ProtoverError::Unparseable)?;
- let lo: Version = low.parse().or(Err(ProtoverError::Unparseable))?;
+ let lo: Version = low.parse().or(Err(ProtoverError::Unparseable))?;
let hi: Version = high.parse().or(Err(ProtoverError::Unparseable))?;
if lo == u32::MAX || hi == u32::MAX {
@@ -457,11 +458,11 @@ impl From<Vec<Version>> for ProtoSet {
if has_range {
let first: Version = match v.first() {
Some(x) => *x,
- None => continue,
+ None => continue,
};
- let last: Version = match v.get(index) {
+ let last: Version = match v.get(index) {
Some(x) => *x,
- None => continue,
+ None => continue,
};
debug_assert!(last == end, format!("last = {}, end = {}", last, end));
@@ -474,7 +475,7 @@ impl From<Vec<Version>> for ProtoSet {
} else {
let last: Version = match v.get(index) {
Some(x) => *x,
- None => continue,
+ None => continue,
};
version_pairs.push((last, last));
v.remove(index);
@@ -498,22 +499,22 @@ mod test {
}
macro_rules! assert_contains_each {
- ($protoset:expr, $versions:expr) => (
+ ($protoset:expr, $versions:expr) => {
for version in $versions {
assert!($protoset.contains(version));
}
- )
+ };
}
macro_rules! test_protoset_contains_versions {
- ($list:expr, $str:expr) => (
+ ($list:expr, $str:expr) => {
let versions: &[Version] = $list;
let protoset: Result<ProtoSet, ProtoverError> = ProtoSet::from_str($str);
assert!(protoset.is_ok());
let p = protoset.unwrap();
assert_contains_each!(p, versions);
- )
+ };
}
#[test]
@@ -555,26 +556,41 @@ mod test {
#[test]
fn test_versions_from_slice_overlap() {
- assert_eq!(Err(ProtoverError::Overlap), ProtoSet::from_slice(&[(1, 3), (2, 4)]));
+ assert_eq!(
+ Err(ProtoverError::Overlap),
+ ProtoSet::from_slice(&[(1, 3), (2, 4)])
+ );
}
#[test]
fn test_versions_from_str_max() {
- assert_eq!(Err(ProtoverError::ExceedsMax), ProtoSet::from_str("4294967295"));
+ assert_eq!(
+ Err(ProtoverError::ExceedsMax),
+ ProtoSet::from_str("4294967295")
+ );
}
#[test]
fn test_versions_from_slice_max() {
- assert_eq!(Err(ProtoverError::ExceedsMax), ProtoSet::from_slice(&[(4294967295, 4294967295)]));
+ assert_eq!(
+ Err(ProtoverError::ExceedsMax),
+ ProtoSet::from_slice(&[(4294967295, 4294967295)])
+ );
}
#[test]
fn test_protoset_contains() {
let protoset: ProtoSet = ProtoSet::from_slice(&[(0, 5), (7, 9), (13, 14)]).unwrap();
- for x in 0..6 { assert!(protoset.contains(&x), format!("should contain {}", x)); }
- for x in 7..10 { assert!(protoset.contains(&x), format!("should contain {}", x)); }
- for x in 13..15 { assert!(protoset.contains(&x), format!("should contain {}", x)); }
+ for x in 0..6 {
+ assert!(protoset.contains(&x), format!("should contain {}", x));
+ }
+ for x in 7..10 {
+ assert!(protoset.contains(&x), format!("should contain {}", x));
+ }
+ for x in 13..15 {
+ assert!(protoset.contains(&x), format!("should contain {}", x));
+ }
for x in [6, 10, 11, 12, 15, 42, 43, 44, 45, 1234584].iter() {
assert!(!protoset.contains(&x), format!("should not contain {}", x));
@@ -585,7 +601,9 @@ mod test {
fn test_protoset_contains_0_3() {
let protoset: ProtoSet = ProtoSet::from_slice(&[(0, 3)]).unwrap();
- for x in 0..4 { assert!(protoset.contains(&x), format!("should contain {}", x)); }
+ for x in 0..4 {
+ assert!(protoset.contains(&x), format!("should contain {}", x));
+ }
}
macro_rules! assert_protoset_from_vec_contains_all {
@@ -611,7 +629,7 @@ mod test {
#[test]
fn test_protoset_from_vec_unordered() {
- let v: Vec<Version> = vec!(2, 3, 8, 4, 3, 9, 7, 2);
+ let v: Vec<Version> = vec![2, 3, 8, 4, 3, 9, 7, 2];
let ps: ProtoSet = v.into();
assert_eq!(ps.to_string(), "2-4,7-9");