From 53b9c1c8d898a84a10b86f2fc31a7f6c2dfc46d0 Mon Sep 17 00:00:00 2001 From: Metabaron Date: Tue, 12 Nov 2019 11:53:31 +0100 Subject: return Error instead of panicking in from_cargo_metadata --- crates/ra_db/src/input.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'crates/ra_db') 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; use rustc_hash::FxHashSet; use crate::{RelativePath, RelativePathBuf}; -use std::str::FromStr; +use std::{error::Error, str::FromStr}; /// `FileId` is an integer which uniquely identifies a file. File paths are /// messy and system-dependent, so most of the code should work directly with @@ -98,13 +98,18 @@ pub enum Edition { Edition2015, } +#[derive(Debug)] +pub struct ParseEditionError { + pub msg: String, +} + impl FromStr for Edition { - type Err = String; + type Err = ParseEditionError; fn from_str(s: &str) -> Result { match s { "2015" => Ok(Edition::Edition2015), "2018" => Ok(Edition::Edition2018), - _ => Err(format! {"unknown edition: {}" , s}), + _ => Err(ParseEditionError { msg: format!("unknown edition: {}", s) }), } } } -- cgit v1.2.3