Skip to content

Commit

Permalink
move IntoIterator into Handle trait associated type, add Candidate as…
Browse files Browse the repository at this point in the history
…sociated type
  • Loading branch information
jeromegn committed Oct 25, 2024
1 parent ce17b84 commit b6dcd88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/corro-types/src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ type MatchCandidates = IndexMap<TableName, IndexSet<Vec<u8>>>;

#[async_trait]
impl Handle for MatcherHandle {
type Candidate = IndexSet<Vec<u8>>;
type CandidateMatcher = MatchCandidates;

fn id(&self) -> Uuid {
Expand Down
17 changes: 8 additions & 9 deletions crates/corro-types/src/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl<T> HasLen for Vec<T> {

#[async_trait]
pub trait Handle {
type CandidateMatcher;
type Candidate: HasLen;
type CandidateMatcher: IntoIterator<Item = (TableName, Self::Candidate)>;

fn id(&self) -> Uuid;
fn hash(&self) -> &str;
Expand Down Expand Up @@ -110,6 +111,7 @@ pub enum TypedNotifyEvent<T> {

#[async_trait]
impl Handle for UpdateHandle {
type Candidate = IndexMap<Vec<u8>, i64>;
type CandidateMatcher = MatchClCandidates;

fn id(&self) -> Uuid {
Expand Down Expand Up @@ -415,13 +417,10 @@ async fn cmd_loop(
debug!(id = %id, "update loop is done");
}

pub fn match_changes<H, T: HasLen>(
manager: &impl Manager<H>,
changes: &[Change],
db_version: CrsqlDbVersion,
) where
pub fn match_changes<H>(manager: &impl Manager<H>, changes: &[Change], db_version: CrsqlDbVersion)
where
H: Handle + Send + 'static,
H::CandidateMatcher: IntoIterator<Item = (TableName, T)> + Clone + Send,
H::CandidateMatcher: Clone + Send,
{
let trait_type = manager.trait_type();
trace!(
Expand Down Expand Up @@ -482,14 +481,14 @@ pub fn match_changes<H, T: HasLen>(
}
}

pub fn match_changes_from_db_version<H, T: HasLen>(
pub fn match_changes_from_db_version<H>(
manager: &impl Manager<H>,
conn: &Connection,
db_version: CrsqlDbVersion,
) -> rusqlite::Result<()>
where
H: Handle + Send + 'static,
H::CandidateMatcher: IntoIterator<Item = (TableName, T)> + Clone + Send,
H::CandidateMatcher: Clone + Send,
{
let handles = manager.get_handles();
if handles.is_empty() {
Expand Down

0 comments on commit b6dcd88

Please sign in to comment.