Skip to content

ContainerOptionsBuilder::env() should not get owned Vec - #237

Merged
softprops merged 1 commit into
softprops:masterfrom
matthiasbeyer:env
Jan 9, 2021
Merged

softprops merged 1 commit into
softprops:masterfrom
matthiasbeyer:env

Conversation

@matthiasbeyer

Copy link
Copy Markdown
Collaborator

This type signature makes it impossible to dynamically construct a
Vec<String> of environment variables and pass it to the builder.

This patch tries to fix that by making the function only take a
reference to a slice containing the environments.

How did you verify your change:

Added a test.

What (if anything) would need to be called out in the CHANGELOG for the next release:

ContainerOptionsBuilder::env() signature changed


Please take this as a proposal. It is most certainly not the nicest solution for the problem described above.

This type signature makes it impossible to dynamically construct a
Vec<String> of environment variables and pass it to the builder.

This patch tries to fix that by making the function only take a
reference to a slice containing the environments.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
@matthiasbeyer

Copy link
Copy Markdown
Collaborator Author

A possible (user-side) solution would be

let f: Vec<&str> = v.iter().map(|s| s.deref()).collect();

But this is hella ugly IMO.

@elihunter173

Copy link
Copy Markdown
Contributor

Is there any reason to not just use slices like so?

pub fn env(&mut self, envs: &[&str]) -> &mut Self { ... }

@matthiasbeyer

Copy link
Copy Markdown
Collaborator Author

This is what this patch does, but with more flexibility even.

Comment thread src/builder.rs
) -> &mut Self {
envs: E,
) -> &mut Self
where S: AsRef<str> + Serialize,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change. Both ergonomically and for flexibility

@softprops
softprops merged commit ae0d4e8 into softprops:master Jan 9, 2021
@matthiasbeyer
matthiasbeyer deleted the env branch January 9, 2021 16:54
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

Successfully merging this pull request may close these issues.

3 participants