aboutsummaryrefslogtreecommitdiff
path: root/src/rust/protover/protover.rs
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2018-03-21 00:24:46 +0000
committerIsis Lovecruft <isis@torproject.org>2018-04-02 18:27:39 +0000
commitb6059297d7cb76f0e00e2098e38d6677d3033340 (patch)
treebccb1506e4aa864ae335f68abeba10508e4ba6ed /src/rust/protover/protover.rs
parent3df954549232bf5516ba5fce13c66a3ac91524a4 (diff)
downloadtor-b6059297d7cb76f0e00e2098e38d6677d3033340.tar.gz
tor-b6059297d7cb76f0e00e2098e38d6677d3033340.zip
rust: Implement error types for Rust protover implementation.
This will allow us to do actual error handling intra-crate in a more rusty manner, e.g. propogating errors in match statements, conversion between error types, logging messages, etc. * FIXES part of #24031: https://bugs.torproject.org/24031.
Diffstat (limited to 'src/rust/protover/protover.rs')
-rw-r--r--src/rust/protover/protover.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/rust/protover/protover.rs b/src/rust/protover/protover.rs
index fd1f41d780..01d17ac8b4 100644
--- a/src/rust/protover/protover.rs
+++ b/src/rust/protover/protover.rs
@@ -13,6 +13,8 @@ use std::u32;
use tor_log::{LogSeverity, LogDomain};
use external::c_tor_version_as_new_as;
+use errors::ProtoverError;
+
/// The first version of Tor that included "proto" entries in its descriptors.
/// Authorities should use this to decide whether to guess proto lines.
///
@@ -54,7 +56,7 @@ impl fmt::Display for Proto {
///
/// C_RUST_COUPLED: src/or/protover.c `PROTOCOL_NAMES`
impl FromStr for Proto {
- type Err = &'static str;
+ type Err = ProtoverError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
@@ -68,7 +70,7 @@ impl FromStr for Proto {
"LinkAuth" => Ok(Proto::LinkAuth),
"Microdesc" => Ok(Proto::Microdesc),
"Relay" => Ok(Proto::Relay),
- _ => Err("Not a valid protocol type"),
+ _ => Err(ProtoverError::UnknownProtocol),
}
}
}