Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Implicit multi-arg support for builder params? #187

Open
polarathene opened this issue Jun 6, 2024 · 1 comment
Open

docs: Implicit multi-arg support for builder params? #187

polarathene opened this issue Jun 6, 2024 · 1 comment

Comments

@polarathene
Copy link

polarathene commented Jun 6, 2024

The crates.io docs don't touch on this example, but I see methods that have more than a single arg supported:

fn main() {
let collections = Collections::builder()
.name("Nandor".to_string())
.name("Nandor")
.name("Colin".to_string())
.names(HashSet::from(["Nadja", "Laszlo"].map(str::to_string)))
.age("Nandor".to_string(), 0)
.age("Nandor", 759)
.age("Colin".to_string(), 100)
.ages(HashMap::from(
[("Nadja", 650), ("Laszlo", 364)].map(|(k, v)| (k.to_string(), v)),
))

Is this due to something with the generics, or specific to the collections (and specific types listed)?


Can buildstructor support that same feature on a non-collection type?:

// Either of these?
struct Pair<X, Y>(X, Y);
struct Pair<T>(T, T);

// fn new(pair: Pair<String, String>) -> Self
builder().pair("hello", "world")

Or are you restricted to a tuple input vs separate explicit args?:

// Manual construction of `Pair` type required:
builder().pair(("hello", "world"));
builder().pair_x("hello").pair_y("world").build();

// Awkward via separate builder:
builder().pair(
    Pair::builder().x("hello").y("world").build()
).build();
@BrynCooke
Copy link
Owner

It's simply down to the naming of the types of the fields:

Special Vec, Deque, Heap, Set, Map support. Add single or multiple items.

I agree it's not explicit in the docs and it could be improved.

Pair support could be added using the same technique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants