Having spent a number of Codeforces rounds practising the ins and outs of Rust, I think it's finally safe to encourage wider participation in the language. This guide is intended primarily for C++ users who may have taken interest in Rust, but weren't sure if it's feasible for use in timed contests. On Quora, I summarized why Rust is actually a practical choice for contests. So here I'll go over one of my Codeforces submissions in more detail, showing some tips along the way.
This was a fairly typical dynamic programming problem. Right away, you'll notice some differences from your typical C++ submission: - No self-defined macros. Rust has good macro support, but I find plain code to be clearer. - No global variables, except for constants. By scoping things appropriately, I don't have to worry about accidentally forgetting to reset data. - Very few mutable variables: - A Scanner struct, with a polymorphic next() function. It can read space-separated tokens of any type that implements the trait FromStr. - Output via a BufWriter. This is needed for speed, if you have to write a large number of lines. It automatically flushes when it goes out of scope, but you'll probably want to flush() manually on interactive problems! - A mix of imperative-style and functional-style constructions, depending on which is clearer
Overall, my solutions attain much fewer WA verdicts in Rust than they did in C++. Development time is sometimes more, sometimes less, but it gets better with practice. Try it out!