Use of assert_eq()

Is assert_eq() meant to crash the app (ie. exit the program) upon evaluation to false? That means, we should not use this method to evaluate user input?

If so, what is a convenient way to evaluate use user input, say from a web form?

asserts in Rust and most languages are intended as fault finding aids. They should never fire off in normal running. They are there to halt everything with a meaningful message in cases when something is very wrong with the logic of your code.

How you evaluate, clean, or otherwise handle user input is as per any other language. Have a look at str - Rust for starters.

2 Likes

Good explanation and just what I thought! Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.