Skip to content

Commit

Permalink
Use a single type
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 24, 2024
1 parent 5021f3f commit 1f11f8a
Show file tree
Hide file tree
Showing 10 changed files with 580 additions and 228 deletions.
20 changes: 18 additions & 2 deletions crates/distribution-types/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ impl Display for FileLocation {
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
rkyv::Archive,
rkyv::Deserialize,
rkyv::Serialize,
Expand All @@ -153,6 +151,24 @@ impl Display for FileLocation {
#[archive_attr(derive(Debug))]
pub struct UrlString(String);

impl serde::Serialize for UrlString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
String::serialize(&self.0, serializer)
}
}

impl<'de> serde::de::Deserialize<'de> for UrlString {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::de::Deserializer<'de>,
{
String::deserialize(deserializer).map(UrlString)
}
}

impl UrlString {
/// Converts a [`UrlString`] to a [`Url`].
pub fn to_url(&self) -> Url {
Expand Down
7 changes: 3 additions & 4 deletions crates/distribution-types/src/index_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl FromStr for IndexUrl {

fn from_str(s: &str) -> Result<Self, Self::Err> {
let path = Path::new(s);
let url = if path.exists() {
let url = if Path::new(s).exists() {
VerbatimUrl::from_path(path)?
} else {
VerbatimUrl::parse_url(s)?
Expand Down Expand Up @@ -248,9 +248,8 @@ impl FromStr for FlatIndexLocation {
type Err = IndexUrlError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let path = Path::new(s);
let url = if path.exists() {
VerbatimUrl::from_path(path)?
let url = if Path::new(s).exists() {
VerbatimUrl::from_path(s)?
} else {
VerbatimUrl::parse_url(s)?
};
Expand Down
Loading

0 comments on commit 1f11f8a

Please sign in to comment.