Skip to content

Commit a70116a

Browse files
authored
Merge pull request #3047 from lann/app-arc-locked
app: Wrap inner LockedApp in Arc
2 parents f9504a8 + 18b228a commit a70116a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

crates/app/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![deny(missing_docs)]
88

99
use std::collections::HashSet;
10+
use std::sync::Arc;
1011

1112
use serde::Deserialize;
1213
use serde_json::Value;
@@ -37,7 +38,7 @@ pub type ValidatorFn = dyn Fn(&App, &[&str]) -> anyhow::Result<()>;
3738
#[derive(Debug, Clone)]
3839
pub struct App {
3940
id: String,
40-
locked: LockedApp,
41+
locked: Arc<LockedApp>,
4142
}
4243

4344
impl App {
@@ -46,7 +47,7 @@ impl App {
4647
pub fn new(id: impl Into<String>, locked: LockedApp) -> Self {
4748
Self {
4849
id: id.into(),
49-
locked,
50+
locked: Arc::new(locked),
5051
}
5152
}
5253

@@ -170,7 +171,7 @@ impl App {
170171
/// Scrubs the locked app to only contain the given list of components
171172
/// Introspects the LockedApp to find and selectively retain the triggers that correspond to those components
172173
fn retain_components(
173-
mut self,
174+
self,
174175
retained_components: &[&str],
175176
validators: &[&ValidatorFn],
176177
) -> Result<LockedApp> {
@@ -187,11 +188,10 @@ impl App {
187188
_ => None,
188189
})
189190
.collect();
190-
self.locked
191-
.components
192-
.retain(|c| component_ids.contains(&c.id));
193-
self.locked.triggers.retain(|t| trigger_ids.contains(&t.id));
194-
Ok(self.locked)
191+
let mut locked = Arc::unwrap_or_clone(self.locked);
192+
locked.components.retain(|c| component_ids.contains(&c.id));
193+
locked.triggers.retain(|t| trigger_ids.contains(&t.id));
194+
Ok(locked)
195195
}
196196

197197
/// Validates that all components specified to be retained actually exist in the app

0 commit comments

Comments
 (0)