From 307c6fec618d5e509c754362687253ef44bb5f3f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Jul 2020 09:53:53 +0200 Subject: Use CrateName for semantic names --- crates/ra_project_model/src/project_json.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'crates/ra_project_model/src/project_json.rs') diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs index 4b5dcd634..9fe1e2dcb 100644 --- a/crates/ra_project_model/src/project_json.rs +++ b/crates/ra_project_model/src/project_json.rs @@ -4,9 +4,9 @@ use std::path::PathBuf; use paths::{AbsPath, AbsPathBuf}; use ra_cfg::CfgOptions; -use ra_db::{CrateId, Dependency, Edition}; +use ra_db::{CrateId, CrateName, Dependency, Edition}; use rustc_hash::FxHashSet; -use serde::Deserialize; +use serde::{de, Deserialize}; use stdx::split_delim; /// Roots and crates that compose this Rust project. @@ -50,7 +50,7 @@ impl ProjectJson { .into_iter() .map(|dep_data| Dependency { crate_id: CrateId(dep_data.krate as u32), - name: dep_data.name.into(), + name: dep_data.name, }) .collect::>(), cfg: { @@ -113,5 +113,14 @@ struct DepData { /// Identifies a crate by position in the crates array. #[serde(rename = "crate")] krate: usize, - name: String, + #[serde(deserialize_with = "deserialize_crate_name")] + name: CrateName, +} + +fn deserialize_crate_name<'de, D>(de: D) -> Result +where + D: de::Deserializer<'de>, +{ + let name = String::deserialize(de)?; + CrateName::new(&name).map_err(|err| de::Error::custom(format!("invalid crate name: {:?}", err))) } -- cgit v1.2.3