aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src/input.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-12 15:30:36 +0000
committerGitHub <[email protected]>2019-11-12 15:30:36 +0000
commit2549be750e4c611a582bc0845b1da71e131f1118 (patch)
treefec19f32a3b9dd7ced95281b291674ed7ee3a4cd /crates/ra_db/src/input.rs
parent55f3ff241a2105d2903266703474acbd24a85e84 (diff)
parentdae087656abf5d120cd9c051bf4fc446fca101e1 (diff)
Merge #2217
2217: Implement FromStr for enum Edition r=matklad a=clemarescx Just did this as I came across the comment in the code asking for implementing `std::str::FromStr` for `input::Edition`. Not sure what was meant by "proper error handling" though, `panic!` with a descriptive message might not be it :sweat_smile: Co-authored-by: Metabaron <[email protected]>
Diffstat (limited to 'crates/ra_db/src/input.rs')
-rw-r--r--crates/ra_db/src/input.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 60f7dc881..c0d95a13f 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -13,6 +13,7 @@ use ra_syntax::SmolStr;
13use rustc_hash::FxHashSet; 13use rustc_hash::FxHashSet;
14 14
15use crate::{RelativePath, RelativePathBuf}; 15use crate::{RelativePath, RelativePathBuf};
16use std::str::FromStr;
16 17
17/// `FileId` is an integer which uniquely identifies a file. File paths are 18/// `FileId` is an integer which uniquely identifies a file. File paths are
18/// messy and system-dependent, so most of the code should work directly with 19/// messy and system-dependent, so most of the code should work directly with
@@ -97,12 +98,18 @@ pub enum Edition {
97 Edition2015, 98 Edition2015,
98} 99}
99 100
100impl Edition { 101#[derive(Debug)]
101 //FIXME: replace with FromStr with proper error handling 102pub struct ParseEditionError {
102 pub fn from_string(s: &str) -> Edition { 103 pub msg: String,
104}
105
106impl FromStr for Edition {
107 type Err = ParseEditionError;
108 fn from_str(s: &str) -> Result<Self, Self::Err> {
103 match s { 109 match s {
104 "2015" => Edition::Edition2015, 110 "2015" => Ok(Edition::Edition2015),
105 "2018" | _ => Edition::Edition2018, 111 "2018" => Ok(Edition::Edition2018),
112 _ => Err(ParseEditionError { msg: format!("unknown edition: {}", s) }),
106 } 113 }
107 } 114 }
108} 115}