Ignoring most of a data structure

Some data structures contains a great many data values, and it would be inconvenient to have to go through and list each one of them in each pattern we want to match against. Fortunately, Rust has a shorthand syntax that means everything else is a don't care.

To do that, we can include .. at the end of the pattern, like so:

if let DemoStruct {id: 40, ..} = source5 {
println!("id is 40, don't care about the rest");
}

That has the same effect as listing out all of the structure's contained variables, except the ones we've explicitly described in the pattern, and matching each one to an _.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.131.212