ralfbiedert / cheats.rs

Rust Language Cheat Sheet - https://cheats.rs
https://cheats.rs
4.09k stars 382 forks source link

add example for string concatenation to demonstrate what to do when the LHS implements fmt:: or io::Write #166

Closed cosmobobak closed 2 years ago

cosmobobak commented 2 years ago

image of my proposed addition: image

ralfbiedert commented 2 years ago

Thanks. We can add write here, but I'd explain something like "Append y to x ..."? I might be off here but semantically concatenate to me implies c=a+b, while append is a+=b.

cosmobobak commented 2 years ago

that's fair! the existing example is correct if both strings need to live beyond their concatenation (assuming format!("{x}{y}") correctly creates a String::with_capacity(x.len() + y.len()), that is) - I just saw the footnote and wanted to provide an example. Now that I re-read this, i should probably also add the '21 tag because my example relies on the new string interpolation syntax

cosmobobak commented 2 years ago

okay, i think I've largely cleared up your objections, any major problems you can see here? image

ralfbiedert commented 2 years ago

Thanks!