mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Implement FromStr for enum Edition
This commit is contained in:
parent
f5e1b0f97c
commit
b69738590c
3 changed files with 14 additions and 8 deletions
|
@ -13,6 +13,7 @@ use ra_syntax::SmolStr;
|
|||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::{RelativePath, RelativePathBuf};
|
||||
use std::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
|
||||
|
@ -97,12 +98,13 @@ pub enum Edition {
|
|||
Edition2015,
|
||||
}
|
||||
|
||||
impl Edition {
|
||||
//FIXME: replace with FromStr with proper error handling
|
||||
pub fn from_string(s: &str) -> Edition {
|
||||
impl FromStr for Edition {
|
||||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"2015" => Edition::Edition2015,
|
||||
"2018" | _ => Edition::Edition2018,
|
||||
"2015" => Ok(Edition::Edition2015),
|
||||
"2018" => Ok(Edition::Edition2018),
|
||||
_ => Err(format! {"unknown edition: {}" , s}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue