diff --git a/crates/ruma-state-res/src/lib.rs b/crates/ruma-state-res/src/lib.rs index 327462e7..6e7620ea 100644 --- a/crates/ruma-state-res/src/lib.rs +++ b/crates/ruma-state-res/src/lib.rs @@ -61,7 +61,7 @@ impl StateResolution { room_version: &RoomVersionId, state_sets: &[StateMap], auth_events: Vec>, - fetch_event: &F, + fetch_event: F, ) -> Result> where E: Event, @@ -105,7 +105,7 @@ impl StateResolution { // Get only the control events with a state_key: "" or ban/kick event (sender != state_key) let control_events = all_conflicted .iter() - .filter(|id| is_power_event_id(id, fetch_event)) + .filter(|id| is_power_event_id(id, &fetch_event)) .cloned() .collect::>(); @@ -113,7 +113,7 @@ impl StateResolution { let sorted_control_levels = StateResolution::reverse_topological_power_sort( &control_events, &all_conflicted, - fetch_event, + &fetch_event, ); debug!("SRTD {:?}", sorted_control_levels); @@ -124,7 +124,7 @@ impl StateResolution { &room_version, &sorted_control_levels, &clean, - fetch_event, + &fetch_event, )?; debug!("AUTHED {:?}", resolved_control.iter().collect::>()); @@ -149,7 +149,7 @@ impl StateResolution { debug!("PL {:?}", power_event); let sorted_left_events = - StateResolution::mainline_sort(&events_to_resolve, power_event, fetch_event); + StateResolution::mainline_sort(&events_to_resolve, power_event, &fetch_event); debug!("SORTED LEFT {:?}", sorted_left_events.iter().collect::>()); @@ -157,7 +157,7 @@ impl StateResolution { &room_version, &sorted_left_events, &resolved_control, // The control events are added to the final resolved state - fetch_event, + &fetch_event, )?; // Add unconflicted state to the resolved state @@ -234,7 +234,7 @@ impl StateResolution { pub fn reverse_topological_power_sort( events_to_sort: &[EventId], auth_diff: &BTreeSet, - fetch_event: &F, + fetch_event: F, ) -> Vec where E: Event, @@ -248,7 +248,7 @@ impl StateResolution { &mut graph, event_id, auth_diff, - fetch_event, + &fetch_event, ); // TODO: if these functions are ever made async here @@ -259,7 +259,7 @@ impl StateResolution { // This is used in the `key_fn` passed to the lexico_topo_sort fn let mut event_to_pl = BTreeMap::new(); for event_id in graph.keys() { - let pl = StateResolution::get_power_level_for_sender(event_id, fetch_event); + let pl = StateResolution::get_power_level_for_sender(event_id, &fetch_event); info!("{} power level {}", event_id, pl); event_to_pl.insert(event_id.clone(), pl); @@ -350,7 +350,7 @@ impl StateResolution { } /// Find the power level for the sender of `event_id` or return a default value of zero. - fn get_power_level_for_sender(event_id: &EventId, fetch_event: &F) -> i64 + fn get_power_level_for_sender(event_id: &EventId, fetch_event: F) -> i64 where E: Event, F: Fn(&EventId) -> Option>, @@ -404,7 +404,7 @@ impl StateResolution { room_version: &RoomVersion, events_to_check: &[EventId], unconflicted_state: &StateMap, - fetch_event: &F, + fetch_event: F, ) -> Result> where E: Event, @@ -501,7 +501,7 @@ impl StateResolution { pub fn mainline_sort( to_sort: &[EventId], resolved_power_level: Option<&EventId>, - fetch_event: &F, + fetch_event: F, ) -> Vec where E: Event, @@ -545,7 +545,7 @@ impl StateResolution { for ev_id in to_sort.iter() { if let Some(event) = fetch_event(ev_id) { if let Ok(depth) = - StateResolution::get_mainline_depth(Some(event), &mainline_map, fetch_event) + StateResolution::get_mainline_depth(Some(event), &mainline_map, &fetch_event) { order_map.insert( ev_id, @@ -576,7 +576,7 @@ impl StateResolution { fn get_mainline_depth( mut event: Option>, mainline_map: &EventMap, - fetch_event: &F, + fetch_event: F, ) -> Result where E: Event, @@ -608,7 +608,7 @@ impl StateResolution { graph: &mut BTreeMap>, event_id: &EventId, auth_diff: &BTreeSet, - fetch_event: &F, + fetch_event: F, ) where E: Event, F: Fn(&EventId) -> Option>, @@ -633,7 +633,7 @@ impl StateResolution { } } -pub fn is_power_event_id(event_id: &EventId, fetch: &F) -> bool +pub fn is_power_event_id(event_id: &EventId, fetch: F) -> bool where E: Event, F: Fn(&EventId) -> Option>, diff --git a/crates/ruma-state-res/tests/event_sorting.rs b/crates/ruma-state-res/tests/event_sorting.rs index e3fc8ced..e300979d 100644 --- a/crates/ruma-state-res/tests/event_sorting.rs +++ b/crates/ruma-state-res/tests/event_sorting.rs @@ -30,7 +30,7 @@ fn test_event_sort() { // TODO these events are not guaranteed to be sorted but they are resolved, do // we need the auth_chain let sorted_power_events = - StateResolution::reverse_topological_power_sort(&power_events, &auth_chain, &|id| { + StateResolution::reverse_topological_power_sort(&power_events, &auth_chain, |id| { events.get(id).map(Arc::clone) }); @@ -40,7 +40,7 @@ fn test_event_sort() { &RoomVersion::version_6(), &sorted_power_events, &BTreeMap::new(), // unconflicted events - &|id| events.get(id).map(Arc::clone), + |id| events.get(id).map(Arc::clone), ) .expect("iterative auth check failed on resolved events"); @@ -51,7 +51,7 @@ fn test_event_sort() { let power_level = resolved_power.get(&(EventType::RoomPowerLevels, "".to_owned())); - let sorted_event_ids = StateResolution::mainline_sort(&events_to_sort, power_level, &|id| { + let sorted_event_ids = StateResolution::mainline_sort(&events_to_sort, power_level, |id| { events.get(id).map(Arc::clone) }); diff --git a/crates/ruma-state-res/tests/res_with_auth_ids.rs b/crates/ruma-state-res/tests/res_with_auth_ids.rs index b4132233..10be20ea 100644 --- a/crates/ruma-state-res/tests/res_with_auth_ids.rs +++ b/crates/ruma-state-res/tests/res_with_auth_ids.rs @@ -77,7 +77,7 @@ fn ban_with_auth_chains2() { .unwrap() }) .collect(), - &|id| ev_map.get(id).map(Arc::clone), + |id| ev_map.get(id).map(Arc::clone), ) { Ok(state) => state, Err(e) => panic!("{}", e), diff --git a/crates/ruma-state-res/tests/state_res.rs b/crates/ruma-state-res/tests/state_res.rs index 4b46af7b..fdfb13dc 100644 --- a/crates/ruma-state-res/tests/state_res.rs +++ b/crates/ruma-state-res/tests/state_res.rs @@ -266,7 +266,7 @@ fn test_event_map_none() { .unwrap() }) .collect(), - &|id| ev_map.get(id).map(Arc::clone), + |id| ev_map.get(id).map(Arc::clone), ) { Ok(state) => state, Err(e) => panic!("{}", e), diff --git a/crates/ruma-state-res/tests/utils.rs b/crates/ruma-state-res/tests/utils.rs index a04a9194..22074958 100644 --- a/crates/ruma-state-res/tests/utils.rs +++ b/crates/ruma-state-res/tests/utils.rs @@ -121,7 +121,7 @@ pub fn do_check( .unwrap() }) .collect(), - &|id| event_map.get(id).map(Arc::clone), + |id| event_map.get(id).map(Arc::clone), ); match resolved { Ok(state) => state,