RUST: non-exhaustive patterns: `&_` not covered pattern `&_` not covered21 sec read

Tried something like this

Error

non-exhaustive patterns: &_ not covered pattern &_ not covered

What I thought was wrong

I thought it meant you cannot match references

What the real error was

Just had to add all possibilities in match statement

 

Rust Actix web panic when using custom regex1 min read

Using Actix-web v0.7.4

Error – thread ‘arbiter:6461f87e-20ed-4848-9feb-dbe68ab5ea7e:actor’ panicked at ‘index out of bounds: the len is 1 but the index is 1’, /checkout/src/libcore/slice/mod.rs:2079:10

How I corrected it

The loop was accessing an index which didn’t exist. I don’t really know how actix web works or even how Rust works.

pub fn match_with_params  in router.rs in actix-web src was the culprit

So I changed the code to this

 

Learning something new : RUST lang PART 32 min read

Error Handling

In the previous one where we built a guess the number game in rust, we did not handle any errors. The obvious error was that if something other than a number was inputted the program would crash.

Now that I have learnt how to correct this, lets change the code a little bit.

This was the code without error handling.


The parse() method returns a result object. The result object would have Ok() and Err() values. So if it is OK we can run a function with the parsed value passed to it. If it is an error we can handle it gracefully and say “Listen idiot, you have to enter a number. A NUMBAAA”.

For this we use the match function or statement or whatever it is called. It seem to act like the switch statement.

So here is the update code for the number guessing game.

With the loop and game –

There you go rust book, I beat you at your own game.