prop: implement InvalidProperty with Default

This commit is contained in:
Lennart
2024-11-04 20:04:46 +01:00
parent 782d886302
commit 05bd8f2aa0
13 changed files with 56 additions and 86 deletions

View File

@@ -19,7 +19,7 @@ impl<R: Resource> Default for CommonPropertiesExtension<R> {
}
}
#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum CommonPropertiesProp<RT: ResourceType> {
// WebDAV (RFC 2518)

View File

@@ -43,7 +43,7 @@ impl Serialize for UserPrivilegeSet {
}
// TODO: implement Deserialize once we need it
#[derive(Debug, Clone, Deserialize, Default)]
#[derive(Debug, Clone, Deserialize, Default, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct UserPrivilegeSet {
privileges: HashSet<UserPrivilege>,

View File

@@ -32,7 +32,7 @@ impl<T: Serialize + for<'de> Deserialize<'de>> ResourceType for T {}
pub trait Resource: Clone + 'static {
type PropName: ResourcePropName;
type Prop: ResourceProp + From<CommonPropertiesProp<Self::ResourceType>>;
type Prop: ResourceProp + From<CommonPropertiesProp<Self::ResourceType>> + PartialEq;
type Error: ResponseError + From<crate::Error>;
type PrincipalResource: Resource;
type ResourceType: Default + Serialize + for<'de> Deserialize<'de>;
@@ -188,6 +188,12 @@ pub trait InvalidProperty {
fn invalid_property(&self) -> bool;
}
impl<T: Default + PartialEq> InvalidProperty for T {
fn invalid_property(&self) -> bool {
self == &T::default()
}
}
#[async_trait(?Send)]
pub trait ResourceService: Sized + 'static {
type MemberType: Resource<Error = Self::Error>;

View File

@@ -10,7 +10,7 @@ use std::any::type_name;
use std::marker::PhantomData;
use strum::{EnumString, VariantNames};
#[derive(Deserialize, Serialize, Default, Debug)]
#[derive(Deserialize, Serialize, Default, Debug, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub struct Resourcetype {
collection: (),

View File

@@ -9,7 +9,7 @@ pub use tag_name::TagName;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize, From)]
#[derive(Debug, Clone, Deserialize, Serialize, From, PartialEq)]
pub struct HrefElement {
pub href: String,
}