summaryrefslogtreecommitdiff
path: root/src/rust/protover
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2018-03-21 02:09:04 +0000
committerIsis Lovecruft <isis@torproject.org>2018-04-02 19:20:30 +0000
commitaa241e99dedeadf92ca72e29d16ed3e31a439392 (patch)
treef774382a361d10ee196ea5a95b621d31984691b2 /src/rust/protover
parent9abbd23df7104f1f46a172c2eaa62bec0afc6d9c (diff)
downloadtor-aa241e99dedeadf92ca72e29d16ed3e31a439392.tar.gz
tor-aa241e99dedeadf92ca72e29d16ed3e31a439392.zip
rust: Refactor protover::is_supported_here().
This changes `protover::is_supported_here()` to be aware of new datatypes (e.g. don't call `.0` on things which are no longer tuple structs) and also changes the method signature to take borrows, making it faster, threadable, and easier to read (i.e. the caller can know from reading the function signature that the function won't mutate values passed into it). * CHANGE the `protover::is_supported_here()` function to take borrows. * REFACTOR the `protover::is_supported_here()` function to be aware of new datatypes. * FIXES part of #24031: https://bugs.torproject.org/24031
Diffstat (limited to 'src/rust/protover')
-rw-r--r--src/rust/protover/protover.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/rust/protover/protover.rs b/src/rust/protover/protover.rs
index 6f234c61a9..572a13c0f0 100644
--- a/src/rust/protover/protover.rs
+++ b/src/rust/protover/protover.rs
@@ -579,26 +579,25 @@ impl ProtoverVote {
///
/// # Examples
/// ```
-/// use protover::*;
+/// use protover::is_supported_here;
+/// use protover::Protocol;
///
-/// let is_supported = is_supported_here(Proto::Link, 10);
+/// let is_supported = is_supported_here(&Protocol::Link, &10);
/// assert_eq!(false, is_supported);
///
-/// let is_supported = is_supported_here(Proto::Link, 1);
+/// let is_supported = is_supported_here(&Protocol::Link, &1);
/// assert_eq!(true, is_supported);
/// ```
-pub fn is_supported_here(proto: Proto, vers: Version) -> bool {
- let currently_supported = match SupportedProtocols::tor_supported() {
- Ok(result) => result.0,
+pub fn is_supported_here(proto: &Protocol, vers: &Version) -> bool {
+ let currently_supported: ProtoEntry = match ProtoEntry::supported() {
+ Ok(result) => result,
Err(_) => return false,
};
-
- let supported_versions = match currently_supported.get(&proto) {
+ let supported_versions = match currently_supported.get(proto) {
Some(n) => n,
None => return false,
};
-
- supported_versions.0.contains(&vers)
+ supported_versions.contains(vers)
}
/// Older versions of Tor cannot infer their own subprotocols