protoset.rs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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 F: FnMut(&Version) -> bool
  244. {
  245. let mut expanded: Vec<Version> = self.clone().expand();
  246. expanded.retain(f);
  247. *self = expanded.into();
  248. }
  249. }
  250. impl FromStr for ProtoSet {
  251. type Err = ProtoverError;
  252. /// Parse the unique version numbers supported by a subprotocol from a string.
  253. ///
  254. /// # Inputs
  255. ///
  256. /// * `version_string`, a string comprised of "[0-9,-]"
  257. ///
  258. /// # Returns
  259. ///
  260. /// A `Result` whose `Ok` value is a `ProtoSet` holding all of the unique
  261. /// version numbers.
  262. ///
  263. /// The returned `Result`'s `Err` value is an `ProtoverError` appropriate to
  264. /// the error.
  265. ///
  266. /// # Errors
  267. ///
  268. /// This function will error if:
  269. ///
  270. /// * the `version_string` is an equals (`"="`) sign,
  271. /// * the expansion of a version range produces an error (see
  272. /// `expand_version_range`),
  273. /// * any single version number is not parseable as an `u32` in radix 10, or
  274. /// * there are greater than 2^16 version numbers to expand.
  275. ///
  276. /// # Examples
  277. ///
  278. /// ```
  279. /// use std::str::FromStr;
  280. ///
  281. /// use protover::errors::ProtoverError;
  282. /// use protover::protoset::ProtoSet;
  283. ///
  284. /// # fn do_test() -> Result<ProtoSet, ProtoverError> {
  285. /// let protoset: ProtoSet = ProtoSet::from_str("2-5,8")?;
  286. ///
  287. /// assert!(protoset.contains(&5));
  288. /// assert!(!protoset.contains(&10));
  289. ///
  290. /// // We can also equivalently call `ProtoSet::from_str` by doing (all
  291. /// // implementations of `FromStr` can be called this way, this one isn't
  292. /// // special):
  293. /// let protoset: ProtoSet = "4-6,12".parse()?;
  294. ///
  295. /// // Calling it (either way) can take really large ranges (up to `u32::MAX`):
  296. /// let protoset: ProtoSet = "1-70000".parse()?;
  297. /// let protoset: ProtoSet = "1-4294967296".parse()?;
  298. ///
  299. /// // There are lots of ways to get an `Err` from this function. Here are
  300. /// // a few:
  301. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("="));
  302. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("-"));
  303. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("not_an_int"));
  304. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("3-"));
  305. /// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1-,4"));
  306. ///
  307. /// // Things which would get parsed into an _empty_ `ProtoSet` are,
  308. /// // however, legal, and result in an empty `ProtoSet`:
  309. /// assert_eq!(Ok(ProtoSet::default()), ProtoSet::from_str(""));
  310. /// assert_eq!(Ok(ProtoSet::default()), ProtoSet::from_str(",,,"));
  311. /// #
  312. /// # Ok(protoset)
  313. /// # }
  314. /// # fn main() { do_test(); } // wrap the test so we can use the ? operator
  315. /// ```
  316. fn from_str(version_string: &str) -> Result<Self, Self::Err> {
  317. let mut pairs: Vec<(Version, Version)> = Vec::new();
  318. let pieces: ::std::str::Split<char> = version_string.trim().split(',');
  319. for piece in pieces {
  320. let p: &str = piece.trim();
  321. if p.is_empty() {
  322. continue;
  323. } else if p.contains('-') {
  324. let mut pair = p.split('-');
  325. let low = pair.next().ok_or(ProtoverError::Unparseable)?;
  326. let high = pair.next().ok_or(ProtoverError::Unparseable)?;
  327. let lo: Version = low.parse().or(Err(ProtoverError::Unparseable))?;
  328. let hi: Version = high.parse().or(Err(ProtoverError::Unparseable))?;
  329. if lo == u32::MAX || hi == u32::MAX {
  330. return Err(ProtoverError::ExceedsMax);
  331. }
  332. pairs.push((lo, hi));
  333. } else {
  334. let v: u32 = p.parse().or(Err(ProtoverError::Unparseable))?;
  335. if v == u32::MAX {
  336. return Err(ProtoverError::ExceedsMax);
  337. }
  338. pairs.push((v, v));
  339. }
  340. }
  341. // If we were passed in an empty string, or a bunch of whitespace, or
  342. // simply a comma, or a pile of commas, then return an empty ProtoSet.
  343. if pairs.len() == 0 {
  344. return Ok(ProtoSet::default());
  345. }
  346. ProtoSet::from_slice(&pairs[..])
  347. }
  348. }
  349. impl ToString for ProtoSet {
  350. /// Contracts a `ProtoSet` of versions into a string.
  351. ///
  352. /// # Returns
  353. ///
  354. /// A `String` representation of this `ProtoSet` in ascending order.
  355. fn to_string(&self) -> String {
  356. let mut final_output: Vec<String> = Vec::new();
  357. for &(lo, hi) in self.iter() {
  358. if lo != hi {
  359. debug_assert!(lo < hi);
  360. final_output.push(format!("{}-{}", lo, hi));
  361. } else {
  362. final_output.push(format!("{}", lo));
  363. }
  364. }
  365. final_output.join(",")
  366. }
  367. }
  368. /// Checks to see if there is a continuous range of integers, starting at the
  369. /// first in the list. Returns the last integer in the range if a range exists.
  370. ///
  371. /// # Inputs
  372. ///
  373. /// `list`, an ordered vector of `u32` integers of "[0-9,-]" representing the
  374. /// supported versions for a single protocol.
  375. ///
  376. /// # Returns
  377. ///
  378. /// A `bool` indicating whether the list contains a range, starting at the first
  379. /// in the list, a`Version` of the last integer in the range, and a `usize` of
  380. /// the index of that version.
  381. ///
  382. /// For example, if given vec![1, 2, 3, 5], find_range will return true,
  383. /// as there is a continuous range, and 3, which is the last number in the
  384. /// continuous range, and 2 which is the index of 3.
  385. fn find_range(list: &Vec<Version>) -> (bool, Version, usize) {
  386. if list.len() == 0 {
  387. return (false, 0, 0);
  388. }
  389. let mut index: usize = 0;
  390. let mut iterable = list.iter().peekable();
  391. let mut range_end = match iterable.next() {
  392. Some(n) => *n,
  393. None => return (false, 0, 0),
  394. };
  395. let mut has_range = false;
  396. while iterable.peek().is_some() {
  397. let n = *iterable.next().unwrap();
  398. if n != range_end + 1 {
  399. break;
  400. }
  401. has_range = true;
  402. range_end = n;
  403. index += 1;
  404. }
  405. (has_range, range_end, index)
  406. }
  407. impl From<Vec<Version>> for ProtoSet {
  408. fn from(mut v: Vec<Version>) -> ProtoSet {
  409. let mut version_pairs: Vec<(Version, Version)> = Vec::new();
  410. v.sort_unstable();
  411. v.dedup();
  412. 'vector: while !v.is_empty() {
  413. let (has_range, end, index): (bool, Version, usize) = find_range(&v);
  414. if has_range {
  415. let first: Version = match v.first() {
  416. Some(x) => *x,
  417. None => continue,
  418. };
  419. let last: Version = match v.get(index) {
  420. Some(x) => *x,
  421. None => continue,
  422. };
  423. debug_assert!(last == end, format!("last = {}, end = {}", last, end));
  424. version_pairs.push((first, last));
  425. v = v.split_off(index + 1);
  426. if v.len() == 0 {
  427. break 'vector;
  428. }
  429. } else {
  430. let last: Version = match v.get(index) {
  431. Some(x) => *x,
  432. None => continue,
  433. };
  434. version_pairs.push((last, last));
  435. v.remove(index);
  436. }
  437. }
  438. ProtoSet::from_slice(&version_pairs[..]).unwrap_or(ProtoSet::default())
  439. }
  440. }
  441. #[cfg(test)]
  442. mod test {
  443. use super::*;
  444. #[test]
  445. fn test_find_range() {
  446. assert_eq!((false, 0, 0), find_range(&vec![]));
  447. assert_eq!((false, 1, 0), find_range(&vec![1]));
  448. assert_eq!((true, 2, 1), find_range(&vec![1, 2]));
  449. assert_eq!((true, 3, 2), find_range(&vec![1, 2, 3]));
  450. assert_eq!((true, 3, 2), find_range(&vec![1, 2, 3, 5]));
  451. }
  452. macro_rules! assert_contains_each {
  453. ($protoset:expr, $versions:expr) => (
  454. for version in $versions {
  455. assert!($protoset.contains(version));
  456. }
  457. )
  458. }
  459. macro_rules! test_protoset_contains_versions {
  460. ($list:expr, $str:expr) => (
  461. let versions: &[Version] = $list;
  462. let protoset: Result<ProtoSet, ProtoverError> = ProtoSet::from_str($str);
  463. assert!(protoset.is_ok());
  464. let p = protoset.unwrap();
  465. assert_contains_each!(p, versions);
  466. )
  467. }
  468. #[test]
  469. fn test_versions_from_str() {
  470. test_protoset_contains_versions!(&[], "");
  471. test_protoset_contains_versions!(&[1], "1");
  472. test_protoset_contains_versions!(&[1, 2], "1,2");
  473. test_protoset_contains_versions!(&[1, 2, 3], "1-3");
  474. test_protoset_contains_versions!(&[0, 1], "0-1");
  475. test_protoset_contains_versions!(&[1, 2, 5], "1-2,5");
  476. test_protoset_contains_versions!(&[1, 3, 4, 5], "1,3-5");
  477. test_protoset_contains_versions!(&[42, 55, 56, 57, 58], "42,55-58");
  478. }
  479. #[test]
  480. fn test_versions_from_str_ab() {
  481. assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("a,b"));
  482. }
  483. #[test]
  484. fn test_versions_from_str_negative_1() {
  485. assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("-1"));
  486. }
  487. #[test]
  488. fn test_versions_from_str_1exclam() {
  489. assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1,!"));
  490. }
  491. #[test]
  492. fn test_versions_from_str_percent_equal() {
  493. assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("%="));
  494. }
  495. #[test]
  496. fn test_versions_from_str_overlap() {
  497. assert_eq!(Err(ProtoverError::Overlap), ProtoSet::from_str("1-3,2-4"));
  498. }
  499. #[test]
  500. fn test_versions_from_slice_overlap() {
  501. assert_eq!(Err(ProtoverError::Overlap), ProtoSet::from_slice(&[(1, 3), (2, 4)]));
  502. }
  503. #[test]
  504. fn test_versions_from_str_max() {
  505. assert_eq!(Err(ProtoverError::ExceedsMax), ProtoSet::from_str("4294967295"));
  506. }
  507. #[test]
  508. fn test_versions_from_slice_max() {
  509. assert_eq!(Err(ProtoverError::ExceedsMax), ProtoSet::from_slice(&[(4294967295, 4294967295)]));
  510. }
  511. #[test]
  512. fn test_protoset_contains() {
  513. let protoset: ProtoSet = ProtoSet::from_slice(&[(0, 5), (7, 9), (13, 14)]).unwrap();
  514. for x in 0..6 { assert!(protoset.contains(&x), format!("should contain {}", x)); }
  515. for x in 7..10 { assert!(protoset.contains(&x), format!("should contain {}", x)); }
  516. for x in 13..15 { assert!(protoset.contains(&x), format!("should contain {}", x)); }
  517. for x in [6, 10, 11, 12, 15, 42, 43, 44, 45, 1234584].iter() {
  518. assert!(!protoset.contains(&x), format!("should not contain {}", x));
  519. }
  520. }
  521. #[test]
  522. fn test_protoset_contains_0_3() {
  523. let protoset: ProtoSet = ProtoSet::from_slice(&[(0, 3)]).unwrap();
  524. for x in 0..4 { assert!(protoset.contains(&x), format!("should contain {}", x)); }
  525. }
  526. macro_rules! assert_protoset_from_vec_contains_all {
  527. ($($x:expr),*) => (
  528. let vec: Vec<Version> = vec!($($x),*);
  529. let protoset: ProtoSet = vec.clone().into();
  530. for x in vec.iter() {
  531. assert!(protoset.contains(&x));
  532. }
  533. )
  534. }
  535. #[test]
  536. fn test_protoset_from_vec_123() {
  537. assert_protoset_from_vec_contains_all!(1, 2, 3);
  538. }
  539. #[test]
  540. fn test_protoset_from_vec_0_315() {
  541. assert_protoset_from_vec_contains_all!(0, 1, 2, 3, 15);
  542. }
  543. #[test]
  544. fn test_protoset_from_vec_unordered() {
  545. let v: Vec<Version> = vec!(2, 3, 8, 4, 3, 9, 7, 2);
  546. let ps: ProtoSet = v.into();
  547. assert_eq!(ps.to_string(), "2-4,7-9");
  548. }
  549. #[test]
  550. fn test_protoset_into_vec() {
  551. let ps: ProtoSet = "1-13,42,9001,4294967294".parse().unwrap();
  552. let v: Vec<Version> = ps.into();
  553. assert!(v.contains(&7));
  554. assert!(v.contains(&9001));
  555. assert!(v.contains(&4294967294));
  556. }
  557. }
  558. #[cfg(all(test, feature = "bench"))]
  559. mod bench {
  560. use super::*;
  561. }