The two questions you should be asking

The code is a bit of head-scratcher. Surely we should have been able to use something similar to the following code?

let value = MyFirstEnum::TupleType(3.14, 1, "Hello".to_owned()); 

And then use value.2 to obtain the string part directly within the println! statement, instead of the if let construct?

The reason why we can't is that enum variants aren't their own type, so as soon as we create the preceding value, above it is immediately lost.

The second question should be: What is the if let construct?

In Rust, if let is used as a way to perform certain types of pattern-matching.

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

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