-
Notifications
You must be signed in to change notification settings - Fork 27
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
Move from pass-by-value builder style API to pass-by-reference #220
Comments
I feel like this is what the For example, w/ pass-by-value that last example is just: builder = requirements.fold(builder, |b, req| b.requires(req)); Similarly, for your other examples, it could be handled similarly, // This can be created by reading in a file
let files = [
("./tests/assets/SOURCES/example_config.toml", FileOptions::new("/etc/rpm-basic/example_config.toml").is_config()),
("./tests/assets/SOURCES/multiplication_tables.py", FileOptions::new("/usr/bin/rpm-basic")),
("", FileOptions::new("/usr/lib/rpm-basic").mode(FileMode::Dir { permissions: 0o644 })),
("", FileOptions::new("/usr/lib/rpm-basic/module").mode(FileMode::Dir { permissions: 0o755 }))
];
builder = files.try_fold(builder, |b, (dest, opts)| {
b.with_file(dest, opts)
})?; |
Well, you say "just" but that's a lot of boilerplate that ultimately does not really need to be there. If there's no particular benefit from passing by ownership in this context, then why sacrifice usability to do so? |
I think I see your point (I hope I didn't offend w/ my usage of just). Since it looks like in your example you're passing back However, this last portion, for req in requirements {
builder.requires(req);
} Seemed to conflict w/ the stated problem of I wanted to point out that since an iterator adapter exists, you could make this improvement today via an extension function that can reduce/fold state without needing to change the existing api. And turn this into a 1 liner on the consumer side, builder.requires(requirements); |
I don't see how it's a conflict, exactly. I agree that you can do it via iterator adapter, but I'm not certain that it's the most ergonomic way. Another potential reason, though, is that I'd kinda like to expose Python bindings eventually and I think simple reference-based APIs would make that easier. |
The current style isn't very readable for RPMs of even average complexity, e.g.
You can do minor things like adding line breaks, but that's not the only issue. Say you wanted to build an RPM from JSON, or user input or something at runtime, and you need to intertwine the builder with loops and if statements. This can be done but you would need to constantly re-assign the variable e.g. #193 (comment)
What we could potentially do instead, is switch to pass-by-reference style. e.g.
That would simplify intertwining logic into the builder construction.
The text was updated successfully, but these errors were encountered: