Skip to content

Commit 69437a9

Browse files
authored
Merge branch 'main' into receivers-mtls
2 parents db38f89 + dfca971 commit 69437a9

File tree

12 files changed

+1173
-511
lines changed

12 files changed

+1173
-511
lines changed

rust/otap-dataflow/crates/otap/src/accessory/slots.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,31 @@ impl<UData> State<UData> {
8181
Some((key, ures))
8282
}
8383

84+
/// Modify user data in a slot (if key is valid).
85+
#[must_use]
86+
pub fn get_mut(&mut self, key: Key) -> Option<&mut UData> {
87+
self.slots.get_mut(key)
88+
}
89+
90+
/// Modify user data in a slot with a function. Return true for
91+
/// the slot to stay alive.
92+
#[must_use]
93+
pub fn mutate<F>(&mut self, key: Key, mut f: F) -> Option<UData>
94+
where
95+
F: FnMut(&mut UData) -> bool,
96+
{
97+
if self
98+
.slots
99+
.get_mut(key)
100+
.map(|value| !f(value))
101+
.unwrap_or(false)
102+
{
103+
self.slots.remove(key)
104+
} else {
105+
None
106+
}
107+
}
108+
84109
/// Take user data from a slot (if key is valid).
85110
#[must_use]
86111
pub fn take(&mut self, key: Key) -> Option<UData> {
@@ -89,7 +114,7 @@ impl<UData> State<UData> {
89114

90115
/// Take and drop the user data (if key is valid).
91116
pub fn cancel(&mut self, key: Key) {
92-
let _ = self.take(key);
117+
_ = self.take(key);
93118
}
94119
}
95120

0 commit comments

Comments
 (0)