declare profile.addons unique by transport_url
use crate::constants::OFFICIAL_ADDONS;
use crate::types::addon::Descriptor;
use crate::types::profile::{Auth, AuthKey, Settings};
+use crate::types::{UniqueVec, UniqueVecAdapter};
use serde::{Deserialize, Serialize};
+use serde_with::serde_as;
+use url::Url;
pub type UID = Option<String>;
+#[serde_as]
#[derive(Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Profile {
pub auth: Option<Auth>,
+ #[serde_as(as = "UniqueVec<Descriptor, Url, DescriptorUniqueVecAdapter>")]
pub addons: Vec<Descriptor>,
pub settings: Settings,
}
@@ -31,3 +36,11 @@ impl Profile {
self.auth.as_ref().map(|auth| &auth.key)
}
}
+
+struct DescriptorUniqueVecAdapter;
+
+impl UniqueVecAdapter<Descriptor, Url> for DescriptorUniqueVecAdapter {
+ fn hash(value: &Descriptor) -> Url {
+ value.transport_url.to_owned()
+ }
+}
