why not just have two types, one for mutable, and one for immutable strings? str and dynstr/strbuf?
Conceptually, you can assert that in cases like let a = "foo"; a += "bar"; a temporary strbuf string is created, even if the compiler optimises it away and created the final immutable str directly. Patrick Walton wrote: > On 10/30/2011 01:53 PM, David Rajchenbach-Teller wrote: >> If type `str` is indeed (at least partly) mutable, each of these >> functions must copy the `str`, which is rather costly. I wonder if >> there is a type-based mechanism that I could use to guarantee that a >> `str` is never mutated, hopefully some trivial typestate-based pattern >> that currently escapes my grasp. > > For now, @str is what you want. Vector uniqueness is causing all sorts of > problems, and it's possible/probable that > we'll change this in the future. > > Patrick > > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
