Make scenario source transitions explicit

This commit is contained in:
andrussal 2026-03-08 13:44:25 +01:00
parent 6888c18275
commit 3f8e287c68
2 changed files with 16 additions and 9 deletions

View File

@ -569,13 +569,13 @@ impl<E: Application, Caps> Builder<E, Caps> {
#[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<E: Application, Caps> Builder<E, Caps> {
#[must_use]
pub fn with_external_only_sources(mut self) -> Self {
self.sources.set_external_only();
self.sources = self.sources.into_external_only();
self
}

View File

@ -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]