[rust-dev] PSA: ~"string" is probably not what you want

Gábor Lehel illissius at gmail.com
Tue Apr 30 11:26:14 PDT 2013

On Sun, Apr 28, 2013 at 8:14 PM, Patrick Walton <pwalton at mozilla.com> wrote:

> > Is
> > there some way to make it just work, no matter what kind of strings
> > you're comparing?  Perhaps "foo" == (*x) would work, for example?
>  That doesn't work, because it makes the dynamically sized `str` a type,
> which is incoherent. (It would lead to dynamically sized stack frames, or
> structs or enums with infinite size, and so on.)
Couldn't this be relaxed? In other words allow dynamically sized `str` as a
type (and perhaps similarly for other dynamically sized types), but
prohibit those things specifically which would be problematic, i.e. using
it in ways that would require knowing its size? I think this would
essentially mean no variables, members, or parameters of that type, but you
*could* use it as a type argument -- including to the various pointer type
constructors. You might also have a rule whereby dereferencing a variable
when the result would be a dynamically-sized type is allowed *if* the
result is immediately borrowed. Then instead of `impl Eq for {@str, ~str,
&str}`, you would have just `impl Eq for str`, and if you want to compare
an ~str you dereference it.  Which seems logical to me, after all
ostensibly you want to compare the contents and not the pointer.

Your ship was destroyed in a monadic eruption.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20130430/4f01b614/attachment.html>

More information about the Rust-dev mailing list