pub struct UniquenessValidator {
pub scope: Vec<String>,
pub case_sensitive: bool,
pub message: Option<String>,
}Expand description
Record-level uniqueness validation metadata and database lookup behavior.
Fields§
§scope: Vec<String>Additional attributes intended to narrow the uniqueness scope.
Scope metadata is retained even though the current generic record API cannot yet project sibling attribute values for query construction.
case_sensitive: boolWhether string comparisons preserve case.
message: Option<String>Optional custom validation message for higher layers.
Implementations§
Source§impl UniquenessValidator
impl UniquenessValidator
Sourcepub fn scope(self, fields: Vec<String>) -> Self
pub fn scope(self, fields: Vec<String>) -> Self
Sets additional scope fields for the uniqueness rule.
Sourcepub fn case_insensitive(self) -> Self
pub fn case_insensitive(self) -> Self
Marks the validator as case-insensitive for string comparisons.
Sourcepub fn message(self, message: impl Into<String>) -> Self
pub fn message(self, message: impl Into<String>) -> Self
Overrides the default error message recorded by higher layers.
Sourcepub async fn validate_unique<R: Record>(
&self,
attribute: &str,
value: &Value,
record: &R,
db: &DatabaseConnection,
) -> boolwhere
<R::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
<R::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
pub async fn validate_unique<R: Record>(
&self,
attribute: &str,
value: &Value,
record: &R,
db: &DatabaseConnection,
) -> boolwhere
<R::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
<R::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
Checks whether the candidate value is unique for the target attribute.
The current generic implementation validates the requested attribute and excludes the
current record by primary key when present. scope metadata is stored for future use once
generic sibling-attribute access is available across all record types.
Sourcepub fn validate_unique_sync<R: Record>(
&self,
attribute: &str,
value: &Value,
record: &R,
) -> boolwhere
<R::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
<R::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
pub fn validate_unique_sync<R: Record>(
&self,
attribute: &str,
value: &Value,
record: &R,
) -> boolwhere
<R::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
<R::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
Synchronous wrapper for Self::validate_unique.
Trait Implementations§
Source§impl Clone for UniquenessValidator
impl Clone for UniquenessValidator
Source§fn clone(&self) -> UniquenessValidator
fn clone(&self) -> UniquenessValidator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UniquenessValidator
impl Debug for UniquenessValidator
Source§impl Default for UniquenessValidator
impl Default for UniquenessValidator
Source§fn default() -> UniquenessValidator
fn default() -> UniquenessValidator
Source§impl PartialEq for UniquenessValidator
impl PartialEq for UniquenessValidator
impl Eq for UniquenessValidator
impl StructuralPartialEq for UniquenessValidator
Auto Trait Implementations§
impl Freeze for UniquenessValidator
impl RefUnwindSafe for UniquenessValidator
impl Send for UniquenessValidator
impl Sync for UniquenessValidator
impl Unpin for UniquenessValidator
impl UnsafeUnpin for UniquenessValidator
impl UnwindSafe for UniquenessValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more