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

Use Iterator::intersperse in -e argument parsing when Rust 1.64.0 is released #2077

Open
lopopolo opened this issue Aug 12, 2022 · 1 comment
Assignees
Labels
A-frontend Area: Frontends for interpreters, like the `ruby` or `irb` binaries. C-quality Category: Refactoring, cleanup, and quality improvements. S-blocked Status: Marked as blocked ❌ on something else such as other implementation work.

Comments

@lopopolo
Copy link
Member

This code manually joins a bunch of -e flags together:

artichoke/src/ruby.rs

Lines 166 to 175 in 9f2d43c

let mut commands = commands.into_iter();
let mut buf = if let Some(command) = commands.next() {
command
} else {
return Ok(Ok(()));
};
for command in commands {
buf.push("\n");
buf.push(command);
}

Iterator::intersperse will be stabilized in rust-lang/rust#99093. Combined with rust-lang/rust#82121, the code will be able to be rewritten to something like:

let buf = commands
    .into_iter()
    .map(Cow::Owned)
    .intersperse(Cow::Borrowed(OsStr::new("\n"))
    .collect::<OsString>();
@lopopolo lopopolo added S-blocked Status: Marked as blocked ❌ on something else such as other implementation work. A-frontend Area: Frontends for interpreters, like the `ruby` or `irb` binaries. C-quality Category: Refactoring, cleanup, and quality improvements. labels Aug 12, 2022
@lopopolo lopopolo self-assigned this Aug 12, 2022
@lopopolo
Copy link
Member Author

It looks like the stabilization PR for Iterator::intersperse has been reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Frontends for interpreters, like the `ruby` or `irb` binaries. C-quality Category: Refactoring, cleanup, and quality improvements. S-blocked Status: Marked as blocked ❌ on something else such as other implementation work.
Development

No branches or pull requests

1 participant