Skip to content

Commit 3656606

Browse files
committed
Add ValuesMapBuilder::take
ValuesMapBuilder::build is updated to have the more idiomatic behavior of consuming the builder, while 'take' adopts 'build's old behavor of resetting the builder to empty. Also add doc comments to all ValuesMapBuilder methods. Signed-off-by: Lann Martin <lann.martin@fermyon.com>
1 parent 6b1bceb commit 3656606

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

crates/app/src/values.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ pub type ValuesMap = serde_json::Map<String, Value>;
99
pub struct ValuesMapBuilder(ValuesMap);
1010

1111
impl ValuesMapBuilder {
12+
/// Returns a new empty ValuesMapBuilder.
1213
pub fn new() -> Self {
1314
Self::default()
1415
}
1516

17+
/// Inserts a string value into the map.
1618
pub fn string(&mut self, key: impl Into<String>, value: impl Into<String>) -> &mut Self {
1719
self.entry(key, value.into())
1820
}
1921

22+
/// Inserts a string value into the map only if the given Option is Some.
2023
pub fn string_option(
2124
&mut self,
2225
key: impl Into<String>,
@@ -28,6 +31,7 @@ impl ValuesMapBuilder {
2831
self
2932
}
3033

34+
/// Inserts a string array into the map.
3135
pub fn string_array<T: Into<String>>(
3236
&mut self,
3337
key: impl Into<String>,
@@ -36,11 +40,13 @@ impl ValuesMapBuilder {
3640
self.entry(key, iter.into_iter().map(|s| s.into()).collect::<Vec<_>>())
3741
}
3842

43+
/// Inserts an entry into the map using the value's `impl Into<Value>`.
3944
pub fn entry(&mut self, key: impl Into<String>, value: impl Into<Value>) -> &mut Self {
4045
self.0.insert(key.into(), value.into());
4146
self
4247
}
4348

49+
/// Inserts an entry into the map using the value's `impl Serialize`.
4450
pub fn serializable(
4551
&mut self,
4652
key: impl Into<String>,
@@ -51,7 +57,13 @@ impl ValuesMapBuilder {
5157
Ok(self)
5258
}
5359

54-
pub fn build(&mut self) -> ValuesMap {
60+
/// Returns the built ValuesMap.
61+
pub fn build(self) -> ValuesMap {
62+
self.0
63+
}
64+
65+
/// Returns the build ValuesMap and resets the builder to empty.
66+
pub fn take(&mut self) -> ValuesMap {
5567
std::mem::take(&mut self.0)
5668
}
5769
}

crates/trigger/src/locked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl LockedAppBuilder {
130130
let metadata = ValuesMapBuilder::new()
131131
.string_option("description", component.description)
132132
.string_array("allowed_http_hosts", component.wasm.allowed_http_hosts)
133-
.build();
133+
.take();
134134

135135
let source = {
136136
let path = match component.source {

0 commit comments

Comments
 (0)