What is the ".." synatax

I have seen a new piece of synatx I have not seen in Rust before (or I forget)

let mut p = Popen::create(&["ps", "x"], PopenConfig {
    stdout: Redirection::Pipe, ..Default::default()
})?;

What does the .. mean?

Seen here

This is struct update syntax: it's covered in the Book and the Reference. It means that the created PopenConfig object will have its remaining fields filled from the corresponding fields in the object returned by Default::default(). In other words, the stdout field is set to the custom value Redirection::Pipe, while the rest of the fields are set to their default values.

2 Likes

Que a meta question: How is something like that found in the book? I searched for it, got no results

Well, in a bit of a roundabout way: I searched for dot in the Book, saw that one of the chapters was "Defining and Instantiating Structs", and figured that struct update syntax would be covered in that chapter, since it's a part of struct instantiation. From there, I just searched for update syntax in the Reference.

With some rustfmt it is easier to understand.

    let mut p = Popen::create(
        &["ps", "x"],
        PopenConfig {
            stdout: Redirection::Pipe,
            ..Default::default()
        },
    )?;

I had to read the 3 line version a couple of times to figure out what what going on.

1 Like

Yes.

I can answer my own meta question now (having had time to dwell on it)

Here in the appendix there is a chapter Operators and Symbols. And there it is.

Silly me, it is so much easier to find the solution when you know the answer

ta

Not that silly. There are four entires for ".."

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.