-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a newtype for the serialized
PackageId
in Proc Macro Server
- Loading branch information
1 parent
bf30ab7
commit 2955b2b
Showing
4 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
use std::fmt::Display; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
/// A string-serialized `PackageId` from the Scarb workspace. | ||
/// Follows the schema: "crate-name version source-path". | ||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Hash)] | ||
#[repr(transparent)] // Guarantees a backward-compatibility with the previous version. | ||
pub struct SerializedPackageId(pub String); | ||
|
||
impl From<String> for SerializedPackageId { | ||
fn from(value: String) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl Display for SerializedPackageId { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl SerializedPackageId { | ||
pub fn name(&self) -> &str { | ||
self.0 | ||
.split(" ") | ||
.next() | ||
.expect("SerializedPackageId should follow a format `<name> <version> (<source>)`") | ||
} | ||
} | ||
|
||
/// A description of the location in the workspace where particular macro is available. | ||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Hash)] | ||
pub struct ProcMacroScope { | ||
/// Serialized `PackageId` of the package in which context the action occurs. | ||
pub package_id: String, | ||
pub package_id: SerializedPackageId, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters