diff options
author | Metabaron <[email protected]> | 2019-11-12 10:53:31 +0000 |
---|---|---|
committer | Metabaron <[email protected]> | 2019-11-12 11:01:13 +0000 |
commit | 53b9c1c8d898a84a10b86f2fc31a7f6c2dfc46d0 (patch) | |
tree | d7dc144ff0cb0a5b4dc1bf8221cc0bf082cb15ce /crates/ra_db | |
parent | b69738590ca1c4823a030d317e7fa6e918618a4b (diff) |
return Error instead of panicking in from_cargo_metadata
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/input.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index fb9a3297a..472a15f2b 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -13,7 +13,7 @@ use ra_syntax::SmolStr; | |||
13 | use rustc_hash::FxHashSet; | 13 | use rustc_hash::FxHashSet; |
14 | 14 | ||
15 | use crate::{RelativePath, RelativePathBuf}; | 15 | use crate::{RelativePath, RelativePathBuf}; |
16 | use std::str::FromStr; | 16 | use std::{error::Error, str::FromStr}; |
17 | 17 | ||
18 | /// `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 |
19 | /// 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 |
@@ -98,13 +98,18 @@ pub enum Edition { | |||
98 | Edition2015, | 98 | Edition2015, |
99 | } | 99 | } |
100 | 100 | ||
101 | #[derive(Debug)] | ||
102 | pub struct ParseEditionError { | ||
103 | pub msg: String, | ||
104 | } | ||
105 | |||
101 | impl FromStr for Edition { | 106 | impl FromStr for Edition { |
102 | type Err = String; | 107 | type Err = ParseEditionError; |
103 | fn from_str(s: &str) -> Result<Self, Self::Err> { | 108 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
104 | match s { | 109 | match s { |
105 | "2015" => Ok(Edition::Edition2015), | 110 | "2015" => Ok(Edition::Edition2015), |
106 | "2018" => Ok(Edition::Edition2018), | 111 | "2018" => Ok(Edition::Edition2018), |
107 | _ => Err(format! {"unknown edition: {}" , s}), | 112 | _ => Err(ParseEditionError { msg: format!("unknown edition: {}", s) }), |
108 | } | 113 | } |
109 | } | 114 | } |
110 | } | 115 | } |