From 3f8e287c68d3b11ba15309982846f09dbab23067 Mon Sep 17 00:00:00 2001 From: andrussal Date: Sun, 8 Mar 2026 13:44:25 +0100 Subject: [PATCH] Make scenario source transitions explicit --- .../core/src/scenario/definition.rs | 6 +++--- .../core/src/scenario/sources/model.rs | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/testing-framework/core/src/scenario/definition.rs b/testing-framework/core/src/scenario/definition.rs index 44b210c..f656a98 100644 --- a/testing-framework/core/src/scenario/definition.rs +++ b/testing-framework/core/src/scenario/definition.rs @@ -569,13 +569,13 @@ impl Builder { #[must_use] pub fn with_attach_source(mut self, attach: AttachSource) -> Self { - self.sources.set_attach(attach); + self.sources = self.sources.with_attach(attach); self } #[must_use] pub fn with_external_node(mut self, node: ExternalNodeSource) -> Self { - self.sources.add_external_node(node); + self.sources = self.sources.with_external_node(node); self } @@ -591,7 +591,7 @@ impl Builder { #[must_use] pub fn with_external_only_sources(mut self) -> Self { - self.sources.set_external_only(); + self.sources = self.sources.into_external_only(); self } diff --git a/testing-framework/core/src/scenario/sources/model.rs b/testing-framework/core/src/scenario/sources/model.rs index c107d7c..84dc89f 100644 --- a/testing-framework/core/src/scenario/sources/model.rs +++ b/testing-framework/core/src/scenario/sources/model.rs @@ -128,22 +128,29 @@ impl ScenarioSources { Self::ExternalOnly { external } } - pub(crate) fn add_external_node(&mut self, node: ExternalNodeSource) { - match self { + #[must_use] + pub fn with_external_node(mut self, node: ExternalNodeSource) -> Self { + match &mut self { Self::Managed { external } | Self::Attached { external, .. } | Self::ExternalOnly { external } => external.push(node), } + + self } - pub(crate) fn set_attach(&mut self, attach: AttachSource) { + #[must_use] + pub fn with_attach(self, attach: AttachSource) -> Self { let external = self.external_nodes().to_vec(); - *self = Self::Attached { attach, external }; + + Self::Attached { attach, external } } - pub(crate) fn set_external_only(&mut self) { + #[must_use] + pub fn into_external_only(self) -> Self { let external = self.external_nodes().to_vec(); - *self = Self::ExternalOnly { external }; + + Self::ExternalOnly { external } } #[must_use]