Is it Possible to Add One Item of a List at a Time? #245
Closed
ShiromMakkad
started this conversation in
General
Replies: 1 comment 1 reply
-
|
Hi, for this to work, you'll need to use use std::collections::HashMap;
#[derive(bon::Builder)]
struct MyStruct {
#[builder(field)]
properties: HashMap<&'static str, String>,
num: i32,
}
impl<S: my_struct_builder::State> MyStructBuilder<S> {
fn property(mut self, key: &'static str, value: impl Into<String>) -> Self {
self.properties.insert(key, value.into());
self
}
}
fn main() {
MyStruct::builder().num(5).property("test", "test2").build();
MyStruct::builder()
.num(5)
.property("test", "test2")
.property("test2", "test3")
.build();
MyStruct::builder().num(5).build(); // Builds empty hashmap
}Alternatively, consider |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Can I do something like:
I don't really need bon to handle
properties->propertybut the general idea of adding individual values and having access tointowould be really nice. This behavior is in the AWS SDK for Rust and I want to match it.I haven't read the entirety of the docs, but I didn't see anything in the overview or table of contents about this.
Beta Was this translation helpful? Give feedback.
All reactions