Quellcode durchsuchen

use const generic instead of fn param for p2p

This lets the code differentiate for clients and peers at compile time instead
of using a runtime conditional that was always the same in practice.
Justin Tracey vor 2 Jahren
Ursprung
Commit
50f764c68f
3 geänderte Dateien mit 4 neuen und 6 gelöschten Zeilen
  1. 2 2
      src/bin/messenger/state.rs
  2. 1 2
      src/bin/mgen-client.rs
  3. 1 2
      src/bin/mgen-peer.rs

+ 2 - 2
src/bin/messenger/state.rs

@@ -353,6 +353,7 @@ enum IdleGroupActions {
 /// Used for Idle group p2p conversations.
 pub async fn manage_idle_conversation<
     'a,
+    const P2P: bool,
     S: 'a + MessageHolder,
     I: std::iter::ExactSizeIterator<Item = &'a mut StateToWriter<S>>,
     M: StreamMap<'a, S, I> + 'a,
@@ -362,7 +363,6 @@ pub async fn manage_idle_conversation<
     stream_map: &'a mut M,
     our_id: &str,
     group: &str,
-    p2p: bool,
     rng: &mut Xoshiro256PlusPlus,
 ) -> StateMachine {
     log!("{},{},Idle", our_id, group);
@@ -378,7 +378,7 @@ pub async fn manage_idle_conversation<
             send_action(conversation, stream_map.values(), our_id, group, rng).await
         }
         IdleGroupActions::Receive(msg) => {
-            let group = if p2p { None } else { Some(group) };
+            let group = if P2P { None } else { Some(group) };
             receive_action(msg, conversation, stream_map, our_id, group, rng).await
         }
     }

+ 1 - 2
src/bin/mgen-client.rs

@@ -180,13 +180,12 @@ async fn manage_conversation(
     loop {
         state_machine = match state_machine {
             StateMachine::Idle(conversation) => {
-                manage_idle_conversation(
+                manage_idle_conversation::<false, _, _, _>(
                     conversation,
                     &mut state_from_reader,
                     &mut state_to_writer,
                     &user,
                     &config.group,
-                    false,
                     &mut rng,
                 )
                 .await

+ 1 - 2
src/bin/mgen-peer.rs

@@ -61,13 +61,12 @@ async fn manage_conversation(
     loop {
         state_machine = match state_machine {
             StateMachine::Idle(conversation) => {
-                manage_idle_conversation(
+                manage_idle_conversation::<true, _, _, _>(
                     conversation,
                     &mut state_from_reader,
                     &mut state_to_writers,
                     user,
                     group,
-                    true,
                     &mut rng,
                 )
                 .await