Also, not to mention the fact that we may be embedding large amounts of data in our binary should we try this multiple times:
const FOO: &'static str = "abcdefghijklmnopqrstuvwxyz";
const BAR: &'static str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const BAZ: &'static str = r#"This is a very long text document! Here is the thing:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ultricies tincidunt urna, vitae vehicula diam molestie vel. Cras a sem hendrerit, porttitor lacus nec, ultrices massa. Phasellus tincidunt augue non malesuada volutpat. Donec neque lorem, venenatis et venenatis nec, aliquet eu lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc lacinia congue ipsum, et tincidunt ex tristique eu. In eu diam luctus, finibus elit sed, viverra orci. Nam non dui ante. Fusce feugiat efficitur quam non laoreet. Praesent ut fringilla felis. Sed lacinia orci in massa accumsan, eget ultrices lectus pulvinar.
Cras elementum nulla nec maximus gravida. Vivamus commodo posuere libero, vitae euismod lectus. Mauris sit amet fringilla neque. Aliquam commodo laoreet lacus vitae semper. Integer id mi maximus, bibendum urna vitae, fermentum erat. Sed odio eros, dapibus vitae hendrerit in, vehicula id massa. Morbi feugiat eros ut lobortis sodales. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque eu metus ut sapien scelerisque pulvinar ac in diam. Donec fringilla, mauris lobortis condimentum condimentum, magna ex porta ex, sit amet consequat sapien velit in nisi. Pellentesque pharetra accumsan odio, quis facilisis elit sollicitudin nec. Ut eleifend, elit at tristique commodo, sapien mauris blandit tortor, at elementum tellus augue sit amet justo. Nullam pharetra accumsan velit, iaculis imperdiet ipsum venenatis sed. Curabitur risus augue, consequat et porttitor in, condimentum ac augue.
"#;
//Over here
let foo = FOO + BAZ;
let bar = BAR + BAZ;
let baz = BAZ + BAZ + bar + foo;
Uh-oh! We have lots of repeated memory statically in our binary, while we could have done that with the runtime memory and put it together piece by piece.
Also, another example that wasn't mentioned by @Hyeonu:
const BAR = "abcdefghijklmnopqrstuvwxyz";
let foo = &BAR[2..5] + &BAR[7..15] + &BAR[..] + &BAR[1..23];
What about slicing? Each of those &BAR[..]
expressions is technically &'static str
.