pub struct GenericConflictResolver<T: Conflictable> { /* private fields */ }Expand description
Generic conflict resolver for any Conflictable type
Maintains an index of active items by conflict key for efficient detection.
Works with any type implementing the Conflictable trait.
§Example
use peat_protocol::policy::{GenericConflictResolver, LastWriteWinsPolicy, Conflictable, ConflictResult};
// Create a resolver for your type
let resolver = GenericConflictResolver::<MyType>::new();
// Check for conflicts
let result = resolver.check_conflict(&my_item).await;
// Resolve if needed
if let ConflictResult::Conflict(existing) = result {
let policy = LastWriteWinsPolicy;
let winner = resolver.resolve(vec![existing[0].clone(), my_item], &policy)?;
}Implementations§
Source§impl<T: Conflictable> GenericConflictResolver<T>
impl<T: Conflictable> GenericConflictResolver<T>
Sourcepub async fn check_conflict(&self, item: &T) -> ConflictResult<T>
pub async fn check_conflict(&self, item: &T) -> ConflictResult<T>
Check if a new item conflicts with existing items
Returns ConflictResult::Conflict if there are existing items
with overlapping conflict keys.
Sourcepub fn resolve(
&self,
items: Vec<T>,
policy: &dyn ResolutionPolicy<T>,
) -> Result<T>
pub fn resolve( &self, items: Vec<T>, policy: &dyn ResolutionPolicy<T>, ) -> Result<T>
Resolve conflict using the specified policy
Takes a list of conflicting items and returns the “winning” item according to the policy’s logic.
Sourcepub async fn register(&self, item: &T) -> Result<()>
pub async fn register(&self, item: &T) -> Result<()>
Register an item as active (after conflict resolution)
Adds the item to the conflict index for future conflict checks.
Sourcepub async fn unregister(&self, item_id: &str) -> Result<()>
pub async fn unregister(&self, item_id: &str) -> Result<()>
Unregister an item from active tracking
Removes the item from all conflict key indices. Called when an item completes, expires, or is cancelled.
Sourcepub async fn get_all_active(&self) -> Vec<T>
pub async fn get_all_active(&self) -> Vec<T>
Get all active items
Sourcepub async fn active_count(&self) -> usize
pub async fn active_count(&self) -> usize
Get count of active items
Sourcepub async fn get_by_key(&self, key: &str) -> Vec<T>
pub async fn get_by_key(&self, key: &str) -> Vec<T>
Get active items by conflict key
Trait Implementations§
Source§impl<T: Conflictable> Default for GenericConflictResolver<T>
impl<T: Conflictable> Default for GenericConflictResolver<T>
Auto Trait Implementations§
impl<T> Freeze for GenericConflictResolver<T>
impl<T> !RefUnwindSafe for GenericConflictResolver<T>
impl<T> Send for GenericConflictResolver<T>
impl<T> Sync for GenericConflictResolver<T>
impl<T> Unpin for GenericConflictResolver<T>where
T: Unpin,
impl<T> UnsafeUnpin for GenericConflictResolver<T>
impl<T> !UnwindSafe for GenericConflictResolver<T>
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> 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