Small-Size-Optimized (SSO) Strings (Arrays)

Does rust have small size optimized strings (and arrays)?

And are these iterator compatible?

In the standard library the implementation looks straightforward, so I'm guessing it doesn't have that optimization:

There's a crate for small strings: https://crates.io/crates/inlinable_string

Also note that slices (including &str) use fat pointers to store length, so for them there's no extra storage overhead.

Types can be made compatible with iterators by implementing traits such as Iterator/IntoIterator, so standard library strings are not special in that regard.

1 Like

See this thread:

1 Like