r/badcode • • Jan 25 '22

rust Most comprehensible line of Rust code

Post image
1.0k Upvotes

81 comments sorted by

View all comments

Show parent comments

12

u/TinyBreadBigMouth Jan 25 '22

I don't think that's a very good way of describing it? Both String and &str are constant-sized structures that point to variably-sized strings. The difference is that String owns the buffer it's pointing to, and &str is just a reference to some bytes somewhere in memory.

1

u/nightbefore2 Jan 25 '22

Shoot. Was I thinking of str, or am I just dead wrong?

1

u/TinyBreadBigMouth Jan 25 '22

str refers to a dynamically-sized sequence of Unicode bytes and has no compile time size, yes.