From fc88177d75e2427c6904f29ac083fed9d7b15b19 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Wed, 6 Nov 2024 21:28:44 -0500 Subject: [PATCH] Reset session when cloned. --- src/lib.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 84fac69..915b039 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,6 @@ mod test_message { } /// Application client to MoreThanText -#[derive(Clone)] pub struct MoreThanText { session: Option, tx: Sender, @@ -115,6 +114,15 @@ impl MoreThanText { } } +impl Clone for MoreThanText { + fn clone(&self) -> Self { + Self { + session: None, + tx: self.tx.clone(), + } + } +} + #[cfg(test)] mod mtt_client { use super::*; @@ -140,4 +148,12 @@ mod mtt_client { mtt.open_session(None); assert_ne!(mtt.get_id(), id1); } + + #[test] + fn cloned_clients_have_no_session() { + let mut mtt = MoreThanText::new(); + mtt.open_session(None); + let result = mtt.clone(); + assert!(result.session.is_none()); + } }