Hacker News new | ask | show | jobs
by thsowers 2563 days ago
If you haven't already, check out the Rust By Example section on this:

https://doc.rust-lang.org/rust-by-example/std/str.html

1 comments

The frustrating part was concatenation, it was surprisingly annoying to combine a few strings and an int into a single string.
The fastest and easiest way is to use format!.

  let cat = format!("{}{}{}", s1, s2, n);
That doesn't seem too bad (Though it's still no C# with the + operator), I'll check that out next time I'm in the Rust neighborhood. Thanks.
No problem!

I personally only tend to use + when there's two or maybe three things at most, in any language, and then switch to an API like this if it exists for more complex things, no matter the language. I find it much easier to read. YMMV.

(And you can use + in Rust, but you'd have to call .to_string() on the integer first)

steve, think I sent you an email before and you responded, but just wanted to say again the Rust Book is a work of art. Since I read it and emailed you, I completed a fairly non-trivial Grad School project entirely in rust. I took a lot of the shortcuts, but the rust book was an excellent primer.

Best intro documentation of any language I have tried to learn recently.

EDIT for those who havent seen it: https://doc.rust-lang.org/book/

Thank you! <3
They should do string interpolation like C# since C# 5. Really easy to use, type safe and avoids a lot of mistakes.
It is possible to do string interpolation in Rust with a macro:

https://docs.rs/interpolate/0.2.3/interpolate/