Skip to content

Commit

Permalink
attempt to use ref in unique vec adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
nklhtv committed Jun 16, 2022
1 parent c9a722b commit 9927175
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/types/addon/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ impl ManifestCatalog {

struct ManifestCatalogUniqueVecAdapter;

impl UniqueVecAdapter for ManifestCatalogUniqueVecAdapter {
impl<'a> UniqueVecAdapter<'a> for ManifestCatalogUniqueVecAdapter {
type Input = ManifestCatalog;
type Output = (String, String);
fn hash(catalog: &ManifestCatalog) -> (String, String) {
(catalog.id.to_owned(), catalog.r#type.to_owned())
type Output = (&'a String, &'a String);
fn hash(catalog: &'a Self::Input) -> Self::Output {
(&catalog.id, &catalog.r#type)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/types/profile/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ impl Profile {

struct DescriptorUniqueVecAdapter;

impl UniqueVecAdapter for DescriptorUniqueVecAdapter {
impl<'a> UniqueVecAdapter<'a> for DescriptorUniqueVecAdapter {
type Input = Descriptor;
type Output = Url;
fn hash(descriptor: &Descriptor) -> Url {
descriptor.transport_url.to_owned()
type Output = &'a Url;
fn hash(descriptor: &'a Descriptor) -> &Url {
&descriptor.transport_url
}
}
10 changes: 5 additions & 5 deletions src/types/serde_as_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::{DeserializeAs, SerializeAs};
use std::hash::Hash;

pub trait UniqueVecAdapter {
pub trait UniqueVecAdapter<'a> {
type Input;
type Output: Eq + Hash;

fn hash(value: &Self::Input) -> Self::Output;
fn hash(value: &'a Self::Input) -> Self::Output;
}

#[derive(Copy, Clone, Debug, Default)]
Expand All @@ -18,7 +18,7 @@ impl<'de, T, U, A> DeserializeAs<'de, Vec<T>> for UniqueVec<A>
where
T: Deserialize<'de>,
U: Eq + Hash,
A: UniqueVecAdapter<Input = T, Output = U>,
A: UniqueVecAdapter<'de, Input = T, Output = U>,
{
fn deserialize_as<D>(deserializer: D) -> Result<Vec<T>, D::Error>
where
Expand All @@ -29,11 +29,11 @@ where
}
}

impl<T, U, A> SerializeAs<Vec<T>> for UniqueVec<A>
impl<'a, T, U, A> SerializeAs<Vec<T>> for UniqueVec<A>
where
T: Serialize,
U: Eq + Hash,
A: UniqueVecAdapter<Input = T, Output = U>,
A: UniqueVecAdapter<'a, Input = T, Output = U>,
{
fn serialize_as<S>(source: &Vec<T>, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down

0 comments on commit 9927175

Please sign in to comment.