-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae0be0e
commit 5a563c6
Showing
8 changed files
with
151 additions
and
102 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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Compatibility structs for converting between [`IndexUrl`] and [`Index`]. These structs are | ||
//! parsed and deserialized as [`IndexUrl`], but are stored as [`Index`] with the appropriate | ||
//! flags set. | ||
|
||
use serde::{Deserialize, Deserializer, Serialize}; | ||
|
||
use crate::{Index, IndexUrl}; | ||
|
||
macro_rules! impl_index { | ||
($name:ident, $from:expr) => { | ||
#[derive(Debug, Clone, Eq, PartialEq)] | ||
pub struct $name(Index); | ||
|
||
impl From<$name> for Index { | ||
fn from(value: $name) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl From<Index> for $name { | ||
fn from(value: Index) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl Serialize for $name { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
self.0.url().serialize(serializer) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for $name { | ||
fn deserialize<D>(deserializer: D) -> Result<$name, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
IndexUrl::deserialize(deserializer).map($from).map(Self) | ||
} | ||
} | ||
|
||
#[cfg(feature = "schemars")] | ||
impl schemars::JsonSchema for $name { | ||
fn schema_name() -> String { | ||
IndexUrl::schema_name() | ||
} | ||
|
||
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { | ||
IndexUrl::json_schema(gen) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_index!(PipIndex, Index::from_index_url); | ||
impl_index!(PipExtraIndex, Index::from_extra_index_url); | ||
impl_index!(PipFindLinks, Index::from_find_links); |
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
Oops, something went wrong.