Skip to content

Derive Clone for Command and StdioContainer #15566

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

Merged
merged 1 commit into from
Jul 10, 2014

Conversation

japaric
Copy link
Member

@japaric japaric commented Jul 10, 2014

Allows use cases like this one:

use std::io::Command;

fn main() {
    let mut cmd = Command::new("ls");
    cmd.arg("-l");

    for &dir in ["a", "b", "c"].iter() {
        println!("{}", cmd.clone().arg(dir));
    }
}

Output:

ls '-l' 'a'
ls '-l' 'b'
ls '-l' 'c'

Without the clone(), you'll end up with:

ls '-l' 'a'
ls '-l' 'a' 'b'
ls '-l' 'a' 'b' 'c'

cc #15294

@huonw
Copy link
Member

huonw commented Jul 10, 2014

(FWIW, it would be neat if TaskBuilder could similar treatment, but the internals look too complicated for that to be possible now.)

bors added a commit that referenced this pull request Jul 10, 2014
Allows use cases like this one:

``` rust
use std::io::Command;

fn main() {
    let mut cmd = Command::new("ls");
    cmd.arg("-l");

    for &dir in ["a", "b", "c"].iter() {
        println!("{}", cmd.clone().arg(dir));
    }
}
```

Output:
```
ls '-l' 'a'
ls '-l' 'b'
ls '-l' 'c'
```
Without the `clone()`, you'll end up with:
```
ls '-l' 'a'
ls '-l' 'a' 'b'
ls '-l' 'a' 'b' 'c'
```

cc #15294
@bors bors closed this Jul 10, 2014
@bors bors merged commit 6d50828 into rust-lang:master Jul 10, 2014
@aturon
Copy link
Member

aturon commented Jul 16, 2014

@huonw Note that TaskBuilder is set up as a "consuming" builder (the spawn method takes self) because of the inability to clone a Writer in general; that also stands in the way of supporting Clone for TaskBuilder itself. I don't see any way around that, sadly.

@japaric japaric deleted the command-clone branch July 22, 2014 16:21
@japaric japaric mentioned this pull request Feb 27, 2015
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.

5 participants