4 ms·
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 https://doc.rust-lang.org/rust-by
by thsowers 7y 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 https://doc.rust-lang.org/rust-by-example/std/str.html
- Covzire 7y agoThe frustrating part was concatenation, it was surprisingly annoying to combine a few strings and an int into a single string.
- steveklabnik 7y agoThe fastest and easiest way is to use format!. let cat = format!("{}{}{}", s1, s2, n);
- Covzire 7y agoThat 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.
- steveklabnik 7y agoNo 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)
- maxxxxx 7y agoThey should do string interpolation like C# since C# 5. Really easy to use, type safe and avoids a lot of mistakes.
- inlineint 7y agoIt is possible to do string interpolation in Rust with a macro: https://docs.rs/interpolate/0.2.3/interpolate/ https://docs.rs/interpolate/0.2.3/interpolate/
- Hortinstein 7y agosteve, 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/ https://doc.rust-lang.org/book/
- steveklabnik 7y agoThank you! <3