summaryrefslogtreecommitdiff
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 19:24:32 +0000
commit88204f91df3e01b69e79b89ba029b42a4025d11f (patch)
tree679bc6dfd177935f094f78bb1440a5962fa0d996 /src/rust/protover/protover.rs
parent961d2ad597134df0171dbbed2e035ae93e2215c6 (diff)
downloadtor-88204f91df3e01b69e79b89ba029b42a4025d11f.tar.gz
tor-88204f91df3e01b69e79b89ba029b42a4025d11f.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 e5dc69b9a0..8ce182cf1b 100644
--- a/src/rust/protover/protover.rs
+++ b/src/rust/protover/protover.rs
@@ -13,6 +13,8 @@ use std::u32;
use tor_util::strings::NUL_BYTE;
+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.
///
@@ -78,7 +80,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 {
@@ -92,7 +94,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),
}
}
}