Hacker News new | ask | show | jobs
by johnsoft 2000 days ago
Expanding a bit on conversions: C#'s `Convert` conflates several different operations.

Examples:

Convert.ToInt32(String) – This is _parsing_. In Rust, use `parse`.

Convert.ToString(Int32) – This is _stringifying_. In Rust, use `to_string`.

Convert.ToInt64(Int32) – This is an _infallible conversion_. In Rust, use `into`.

Convert.ToInt32(Int64) – This is a _fallible conversion_. In Rust, use `try_into`.

In all these cases, Rust gives you more immediate semantic information about the conversion, and in fewer characters too!