Skip to content

Conversation

@japaric
Copy link
Contributor

@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
Contributor

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
Contributor

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
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 16, 2025
Closes rust-lang/rust-clippy#15555

changelog: [`use_self`]: Check structs and enums
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