protoset.rs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. // Copyright (c) 2018, The Tor Project, Inc.
  2. // Copyright (c) 2018, isis agora lovecruft
  3. // See LICENSE for licensing information
  4. //! Sets for lazily storing ordered, non-overlapping ranges of integers.
  5. use std::slice;
  6. use std::str::FromStr;
  7. use std::u32;
  8. use errors::ProtoverError;
  9. /// A single version number.
  10. pub type Version = u32;
  11. /// A `ProtoSet` stores an ordered `Vec<T>` of `(low, high)` pairs of ranges of
  12. /// non-overlapping protocol versions.
  13. ///
  14. /// # Examples
  15. ///
  16. /// ```
  17. /// use std::str::FromStr;
  18. ///
  19. /// use protover::errors::ProtoverError;
  20. /// use protover::protoset::ProtoSet;
  21. /// use protover::protoset::Version;
  22. ///
  23. /// # fn do_test() -> Result<ProtoSet, ProtoverError> {
  24. /// let protoset: ProtoSet = ProtoSet::from_str("3-5,8")?;
  25. ///
  26. /// // We could also equivalently call:
  27. /// let protoset: ProtoSet = "3-5,8".parse()?;
  28. ///
  29. /// assert!(protoset.contains(&4));
  30. /// assert!(!protoset.contains(&7));
  31. ///
  32. /// let expanded: Vec<Version> = protoset.clone().into();
  33. ///
  34. /// assert_eq!(&expanded[..], &[3, 4, 5, 8]);
  35. ///
  36. /// let contracted: String = protoset.clone().to_string();
  37. ///
  38. /// assert_eq!(contracted, "3-5,8".to_string());
  39. /// # Ok(protoset)
  40. /// # }
  41. /// # fn main() { do_test(); } // wrap the test so we can use the ? operator
  42. #[derive(Clone, Debug, Eq, PartialEq, Hash)]
  43. pub struct ProtoSet {
  44. pub(crate) pairs: Vec<(Version, Version)>,
  45. }
  46. impl Default for ProtoSet {
  47. fn default() -> Self {
  48. let pairs: Vec<(Version, Version)> = Vec::new();
  49. ProtoSet { pairs }
  50. }
  51. }
  52. impl<'a> ProtoSet {
  53. /// Create a new `ProtoSet` from a slice of `(low, high)` pairs.
  54. ///
  55. /// # Inputs
  56. ///
  57. /// We do not assume the input pairs are deduplicated or ordered.
  58. pub fn from_slice(low_high_pairs: &'a [(Version, Version)]) -> Result<Self, ProtoverError> {
  59. let mut pairs: Vec<(Version, Version)> = Vec::with_capacity(low_high_pairs.len());
  60. for &(low, high) in low_high_pairs {
  61. pairs.push((low, high));
  62. }
  63. // Sort the pairs without reallocation and remove all duplicate pairs.
  64. pairs.sort_unstable();
  65. pairs.dedup();
  66. ProtoSet { pairs }.is_ok()
  67. }
  68. }
  69. /// Expand this `ProtoSet` to a `Vec` of all its `Version`s.
  70. ///
  71. /// # Examples
  72. ///
  73. /// ```
  74. /// use std::str::FromStr;
  75. /// use protover::protoset::ProtoSet;
  76. /// use protover::protoset::Version;
  77. /// # use protover::errors::ProtoverError;
  78. ///
  79. /// # fn do_test() -> Result<Vec<Version>, ProtoverError> {
  80. /// let protoset: ProtoSet = ProtoSet::from_str("3-5,21")?;
  81. /// let versions: Vec<Version> = protoset.into();
  82. ///
  83. /// assert_eq!(&versions[..], &[3, 4, 5, 21]);
  84. /// #
  85. /// # Ok(versions)
  86. /// # }
  87. /// # fn main() { do_test(); } // wrap the test so we can use the ? operator
  88. /// ```
  89. impl Into<Vec<Version>> for ProtoSet {
  90. fn into(self) -> Vec<Version> {
  91. let mut versions: Vec<Version> = Vec::new();
  92. for &(low, high) in self.iter() {
  93. versions.extend(low..high + 1);
  94. }
  95. versions
  96. }
  97. }
  98. impl ProtoSet {
  99. /// Get an iterator over the `(low, high)` `pairs` in this `ProtoSet`.
  100. pub fn iter(&self) -> slice::Iter<(Version, Version)> {
  101. self.pairs.iter()
  102. }
  103. /// Expand this `ProtoSet` into a `Vec` of all its `Version`s.
  104. ///
  105. /// # Examples
  106. ///
  107. /// ```
  108. /// # use protover::errors::ProtoverError;
  109. /// use protover::protoset::ProtoSet;
  110. ///
  111. /// # fn do_test() -> Result<bool, ProtoverError> {
  112. /// let protoset: ProtoSet = "3-5,9".parse()?;
  113. ///
  114. /// assert_eq!(protoset.expand(), vec![3, 4, 5, 9]);
  115. ///
  116. /// let protoset: ProtoSet = "1,3,5-7".parse()?;
  117. ///
  118. /// assert_eq!(protoset.expand(), vec![1, 3, 5, 6, 7]);
  119. /// #
  120. /// # Ok(true)
  121. /// # }
  122. /// # fn main() { do_test(); } // wrap the test so we can use the ? operator
  123. /// ```
  124. pub fn expand(self) -> Vec<Version> {
  125. self.into()
  126. }
  127. pub fn len(&self) -> usize {
  128. let mut length: usize = 0;
  129. for &(low, high) in self.iter() {
  130. length += (high as usize - low as usize) + 1;
  131. }
  132. length
  133. }
  134. /// Check that this `ProtoSet` is well-formed.
  135. ///
  136. /// This is automatically called in `ProtoSet::from_str()`.
  137. ///
  138. /// # Errors
  139. ///
  140. /// * `ProtoverError::LowGreaterThanHigh`: if its `pairs` were not
  141. /// well-formed, i.e. a `low` in a `(low, high)` was higher than the
  142. /// previous `high`,
  143. /// * `ProtoverError::Overlap`: if one or more of the `pairs` are
  144. /// overlapping,
  145. /// * `ProtoverError::ExceedsMax`: if the number of versions when expanded
  146. /// would exceed `MAX_PROTOCOLS_TO_EXPAND`, and
  147. ///
  148. /// # Returns
  149. ///
  150. /// A `Result` whose `Ok` is this `Protoset`, and whose `Err` is one of the
  151. /// errors enumerated in the Errors section above.
  152. fn is_ok(self) -> Result<ProtoSet, ProtoverError> {
  153. let mut last_high: Version = 0;
  154. for &(low, high) in self.iter() {
  155. if low == u32::MAX || high == u32::MAX {
  156. return Err(ProtoverError::ExceedsMax);
  157. }
  158. if low < last_high {
  159. return Err(ProtoverError::Overlap);
  160. } else if low > high {
  161. return Err(ProtoverError::LowGreaterThanHigh);
  162. }
  163. last_high = high;
  164. }
  165. Ok(self)
  166. }
  167. /// Determine if this `ProtoSet` contains no `Version`s.
  168. ///
  169. /// # Returns
  170. ///
  171. /// * `true` if this `ProtoSet`'s length is zero, and
  172. /// * `false` otherwise.
  173. ///
  174. /// # Examples
  175. ///
  176. /// ```
  177. /// use protover::protoset::ProtoSet;
  178. ///
  179. /// let protoset: ProtoSet = ProtoSet::default();
  180. ///
  181. /// assert!(protoset.is_empty());
  182. /// ```
  183. pub fn is_empty(&self) -> bool {
  184. self.pairs.len() == 0
  185. }
  186. /// Determine if `version` is included within this `ProtoSet`.
  187. ///
  188. /// # Inputs
  189. ///
  190. /// * `version`: a `Version`.
  191. ///
  192. /// # Returns
  193. ///
  194. /// `true` if the `version` is contained within this set; `false` otherwise.
  195. ///
  196. /// # Examples
  197. ///
  198. /// ```
  199. /// # use protover::errors::ProtoverError;
  200. /// use protover::protoset::ProtoSet;
  201. ///
  202. /// # fn do_test() -> Result<ProtoSet, ProtoverError> {
  203. /// let protoset: ProtoSet = ProtoSet::from_slice(&[(0, 5), (7, 9), (13, 14)])?;
  204. ///
  205. /// assert!(protoset.contains(&5));
  206. /// assert!(!protoset.contains(&10));
  207. /// #
  208. /// # Ok(protoset)
  209. /// # }
  210. /// # fn main() { do_test(); } // wrap the test so we can use the ? operator
  211. /// ```
  212. pub fn contains(&self, version: &Version) -> bool {
  213. for &(low, high) in self.iter() {
  214. if low <= *version && *version <= high {
  215. return true;
  216. }
  217. }
  218. false
  219. }
  220. /// Retain only the `Version`s in this `ProtoSet` for which the predicate
  221. /// `F` returns `true`.
  222. ///
  223. /// # Examples
  224. ///
  225. /// ```
  226. /// # use protover::errors::ProtoverError;
  227. /// use protover::protoset::ProtoSet;
  228. ///
  229. /// # fn do_test() -> Result<bool, ProtoverError> {
  230. /// let mut protoset: ProtoSet = "1,3-5,9".parse()?;
  231. ///
  232. /// // Keep only versions less than or equal to 8:
  233. /// protoset.retain(|x| x <= &8);
  234. ///
  235. /// assert_eq!(protoset.expand(), vec![1, 3, 4, 5]);
  236. /// #
  237. /// # Ok(true)
  238. /// # }
  239. /// # fn main() { do_test(); } // wrap the test so we can use the ? operator
  240. /// ```
  241. // XXX we could probably do something more efficient here. —isis
  242. pub fn retain<F>(&mut self, f: F)
  243. where
  244. F: FnMut(&Version) -> bool,
  245. {
  246. let mut expanded: Vec<Version> = self.clone().expand();
  247. expanded.retain(f);
  248. *self = expanded.into();
  249. }
  250. }
  251. impl FromStr for ProtoSet {
  252. type Err = ProtoverError;
  253. /// Parse the unique version numbers supported by a subprotocol from a string.
  254. ///
  255. /// # Inputs
  256. ///
  257. /// * `version_string`, a string comprised of "[0-9,-]"
  258. ///
  259. /// # Returns
  260. ///
  261. /// A `Result` whose `Ok` value is a `ProtoSet` holding all of the unique
  262. /// version numbers.
  263. ///
  264. /// The returned `Result`'s `Err` value is an `ProtoverError` appropriate to
  265. /// the error.
  266. ///
  267. /// # Errors
  268. ///
  269. /// This function will error if:
  270. ///
  271. /// * the `version_string` is an equals (`"="`) sign,
  272. /// * the expansion of a version range produces an error (see
  273. /// `expand_version_range`),
  274. /// * any single version number is not parseable as an `u32` in radix 10, or
  275. /// * there are greater than 2^16 version numbers to expand.
  276. ///
  277. /// # Examples
  278. ///
  279. /// ```
  280. /// use std::str::FromStr;
  281. ///
  282. /// use protover::errors::ProtoverError;
  283. /// use protover::protoset::ProtoSet;
  284. ///
  285. /// # fn do_test() -> Result<ProtoSet, ProtoverError> {
  286. /// let protoset: ProtoSet = ProtoSet::from_str("2-5,8")?;
  287. ///
  288. /// assert!(protoset.contains(&5));
  289. /// assert!(!protoset.contains(&10));
  290. ///
  291. /// // We can also equivalently call `ProtoSet::from_str` by doing (all
  292. /// // implementations of `FromStr` can be called this way, this one isn't
  293. /// // special):
  294. /// let protoset: ProtoSet = "4-6,12".parse()?;
  295. ///
  296. /// // Calling it (either way) can take really large ranges (up to `u32::MAX`):
  297. /// let protoset: ProtoSet = "1-70000".parse()?;
  298. /// let protoset: ProtoSet = "1-4294967296".parse()?;
  299. ///
  300. /// // There are lots of ways to get an `Err` from this function. Here are
  301. /// // a few:
  302. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("="));
  303. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("-"));
  304. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("not_an_int"));
  305. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("3-"));
  306. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1-,4"));
  307. ///
  308. /// // Things which would get parsed into an _empty_ `ProtoSet` are,
  309. /// // however, legal, and result in an empty `ProtoSet`:
  310. /// assert_eq!(Ok(ProtoSet::default()), ProtoSet::from_str(""));
  311. /// assert_eq!(Ok(ProtoSet::default()), ProtoSet::from_str(",,,"));
  312. /// #
  313. /// # Ok(protoset)
  314. /// # }
  315. /// # fn main() { do_test(); } // wrap the test so we can use the ? operator
  316. /// ```
  317. fn from_str(version_string: &str) -> Result<Self, Self::Err> {
  318. let mut pairs: Vec<(Version, Version)> = Vec::new();
  319. let pieces: ::std::str::Split<char> = version_string.trim().split(',');
  320. for piece in pieces {
  321. let p: &str = piece.trim();
  322. if p.is_empty() {
  323. continue;
  324. } else if p.contains('-') {
  325. let mut pair = p.split('-');
  326. let low = pair.next().ok_or(ProtoverError::Unparseable)?;
  327. let high = pair.next().ok_or(ProtoverError::Unparseable)?;
  328. let lo: Version = low.parse().or(Err(ProtoverError::Unparseable))?;
  329. let hi: Version = high.parse().or(Err(ProtoverError::Unparseable))?;
  330. if lo == u32::MAX || hi == u32::MAX {
  331. return Err(ProtoverError::ExceedsMax);
  332. }
  333. pairs.push((lo, hi));
  334. } else {
  335. let v: u32 = p.parse().or(Err(ProtoverError::Unparseable))?;
  336. if v == u32::MAX {
  337. return Err(ProtoverError::ExceedsMax);
  338. }
  339. pairs.push((v, v));
  340. }
  341. }
  342. // If we were passed in an empty string, or a bunch of whitespace, or
  343. // simply a comma, or a pile of commas, then return an empty ProtoSet.
  344. if pairs.len() == 0 {
  345. return Ok(ProtoSet::default());
  346. }
  347. ProtoSet::from_slice(&pairs[..])
  348. }
  349. }
  350. impl ToString for ProtoSet {
  351. /// Contracts a `ProtoSet` of versions into a string.
  352. ///
  353. /// # Returns
  354. ///
  355. /// A `String` representation of this `ProtoSet` in ascending order.
  356. fn to_string(&self) -> String {
  357. let mut final_output: Vec<String> = Vec::new();
  358. for &(lo, hi) in self.iter() {
  359. if lo != hi {
  360. debug_assert!(lo < hi);
  361. final_output.push(format!("{}-{}", lo, hi));
  362. } else {
  363. final_output.push(format!("{}", lo));
  364. }
  365. }
  366. final_output.join(",")
  367. }
  368. }
  369. /// Checks to see if there is a continuous range of integers, starting at the
  370. /// first in the list. Returns the last integer in the range if a range exists.
  371. ///
  372. /// # Inputs
  373. ///
  374. /// `list`, an ordered vector of `u32` integers of "[0-9,-]" representing the
  375. /// supported versions for a single protocol.
  376. ///
  377. /// # Returns
  378. ///
  379. /// A `bool` indicating whether the list contains a range, starting at the first
  380. /// in the list, a`Version` of the last integer in the range, and a `usize` of
  381. /// the index of that version.
  382. ///
  383. /// For example, if given vec![1, 2, 3, 5], find_range will return true,
  384. /// as there is a continuous range, and 3, which is the last number in the
  385. /// continuous range, and 2 which is the index of 3.
  386. fn find_range(list: &Vec<Version>) -> (bool, Version, usize) {
  387. if list.len() == 0 {
  388. return (false, 0, 0);
  389. }
  390. let mut index: usize = 0;
  391. let mut iterable = list.iter().peekable();
  392. let mut range_end = match iterable.next() {
  393. Some(n) => *n,
  394. None => return (false, 0, 0),
  395. };
  396. let mut has_range = false;
  397. while iterable.peek().is_some() {
  398. let n = *iterable.next().unwrap();
  399. if n != range_end + 1 {
  400. break;
  401. }
  402. has_range = true;
  403. range_end = n;
  404. index += 1;
  405. }
  406. (has_range, range_end, index)
  407. }
  408. impl From<Vec<Version>> for ProtoSet {
  409. fn from(mut v: Vec<Version>) -> ProtoSet {
  410. let mut version_pairs: Vec<(Version, Version)> = Vec::new();
  411. v.sort_unstable();
  412. v.dedup();
  413. 'vector: while !v.is_empty() {
  414. let (has_range, end, index): (bool, Version, usize) = find_range(&v);
  415. if has_range {
  416. let first: Version = match v.first() {
  417. Some(x) => *x,
  418. None => continue,
  419. };
  420. let last: Version = match v.get(index) {
  421. Some(x) => *x,
  422. None => continue,
  423. };
  424. debug_assert!(last == end, format!("last = {}, end = {}", last, end));
  425. version_pairs.push((first, last));
  426. v = v.split_off(index + 1);
  427. if v.len() == 0 {
  428. break 'vector;
  429. }
  430. } else {
  431. let last: Version = match v.get(index) {
  432. Some(x) => *x,
  433. None => continue,
  434. };
  435. version_pairs.push((last, last));
  436. v.remove(index);
  437. }
  438. }
  439. ProtoSet::from_slice(&version_pairs[..]).unwrap_or(ProtoSet::default())
  440. }
  441. }
  442. #[cfg(test)]
  443. mod test {
  444. use super::*;
  445. #[test]
  446. fn test_find_range() {
  447. assert_eq!((false, 0, 0), find_range(&vec![]));
  448. assert_eq!((false, 1, 0), find_range(&vec![1]));
  449. assert_eq!((true, 2, 1), find_range(&vec![1, 2]));
  450. assert_eq!((true, 3, 2), find_range(&vec![1, 2, 3]));
  451. assert_eq!((true, 3, 2), find_range(&vec![1, 2, 3, 5]));
  452. }
  453. macro_rules! assert_contains_each {
  454. ($protoset:expr, $versions:expr) => {
  455. for version in $versions {
  456. assert!($protoset.contains(version));
  457. }
  458. };
  459. }
  460. macro_rules! test_protoset_contains_versions {
  461. ($list:expr, $str:expr) => {
  462. let versions: &[Version] = $list;
  463. let protoset: Result<ProtoSet, ProtoverError> = ProtoSet::from_str($str);
  464. assert!(protoset.is_ok());
  465. let p = protoset.unwrap();
  466. assert_contains_each!(p, versions);
  467. };
  468. }
  469. #[test]
  470. fn test_versions_from_str() {
  471. test_protoset_contains_versions!(&[], "");
  472. test_protoset_contains_versions!(&[1], "1");
  473. test_protoset_contains_versions!(&[1, 2], "1,2");
  474. test_protoset_contains_versions!(&[1, 2, 3], "1-3");
  475. test_protoset_contains_versions!(&[0, 1], "0-1");
  476. test_protoset_contains_versions!(&[1, 2, 5], "1-2,5");
  477. test_protoset_contains_versions!(&[1, 3, 4, 5], "1,3-5");
  478. test_protoset_contains_versions!(&[42, 55, 56, 57, 58], "42,55-58");
  479. }
  480. #[test]
  481. fn test_versions_from_str_ab() {
  482. assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("a,b"));
  483. }
  484. #[test]
  485. fn test_versions_from_str_negative_1() {
  486. assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("-1"));
  487. }
  488. #[test]
  489. fn test_versions_from_str_1exclam() {
  490. assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1,!"));
  491. }
  492. #[test]
  493. fn test_versions_from_str_percent_equal() {
  494. assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("%="));
  495. }
  496. #[test]
  497. fn test_versions_from_str_overlap() {
  498. assert_eq!(Err(ProtoverError::Overlap), ProtoSet::from_str("1-3,2-4"));
  499. }
  500. #[test]
  501. fn test_versions_from_slice_overlap() {
  502. assert_eq!(
  503. Err(ProtoverError::Overlap),
  504. ProtoSet::from_slice(&[(1, 3), (2, 4)])
  505. );
  506. }
  507. #[test]
  508. fn test_versions_from_str_max() {
  509. assert_eq!(
  510. Err(ProtoverError::ExceedsMax),
  511. ProtoSet::from_str("4294967295")
  512. );
  513. }
  514. #[test]
  515. fn test_versions_from_slice_max() {
  516. assert_eq!(
  517. Err(ProtoverError::ExceedsMax),
  518. ProtoSet::from_slice(&[(4294967295, 4294967295)])
  519. );
  520. }
  521. #[test]
  522. fn test_protoset_contains() {
  523. let protoset: ProtoSet = ProtoSet::from_slice(&[(0, 5), (7, 9), (13, 14)]).unwrap();
  524. for x in 0..6 {
  525. assert!(protoset.contains(&x), format!("should contain {}", x));
  526. }
  527. for x in 7..10 {
  528. assert!(protoset.contains(&x), format!("should contain {}", x));
  529. }
  530. for x in 13..15 {
  531. assert!(protoset.contains(&x), format!("should contain {}", x));
  532. }
  533. for x in [6, 10, 11, 12, 15, 42, 43, 44, 45, 1234584].iter() {
  534. assert!(!protoset.contains(&x), format!("should not contain {}", x));
  535. }
  536. }
  537. #[test]
  538. fn test_protoset_contains_0_3() {
  539. let protoset: ProtoSet = ProtoSet::from_slice(&[(0, 3)]).unwrap();
  540. for x in 0..4 {
  541. assert!(protoset.contains(&x), format!("should contain {}", x));
  542. }
  543. }
  544. macro_rules! assert_protoset_from_vec_contains_all {
  545. ($($x:expr),*) => (
  546. let vec: Vec<Version> = vec!($($x),*);
  547. let protoset: ProtoSet = vec.clone().into();
  548. for x in vec.iter() {
  549. assert!(protoset.contains(&x));
  550. }
  551. )
  552. }
  553. #[test]
  554. fn test_protoset_from_vec_123() {
  555. assert_protoset_from_vec_contains_all!(1, 2, 3);
  556. }
  557. #[test]
  558. fn test_protoset_from_vec_0_315() {
  559. assert_protoset_from_vec_contains_all!(0, 1, 2, 3, 15);
  560. }
  561. #[test]
  562. fn test_protoset_from_vec_unordered() {
  563. let v: Vec<Version> = vec![2, 3, 8, 4, 3, 9, 7, 2];
  564. let ps: ProtoSet = v.into();
  565. assert_eq!(ps.to_string(), "2-4,7-9");
  566. }
  567. #[test]
  568. fn test_protoset_into_vec() {
  569. let ps: ProtoSet = "1-13,42,9001,4294967294".parse().unwrap();
  570. let v: Vec<Version> = ps.into();
  571. assert!(v.contains(&7));
  572. assert!(v.contains(&9001));
  573. assert!(v.contains(&4294967294));
  574. }
  575. }
  576. #[cfg(all(test, feature = "bench"))]
  577. mod bench {
  578. use super::*;
  579. }