[rust-dev] Syntax of vectors, slices, etc

Rick Richardson rick.richardson at gmail.com
Mon Apr 23 15:21:24 PDT 2012


Should a str be subject to the same syntax? Because it will have
different semantics.

A UTF-8 string  has differently sized characters, so you can't treat
it as a vector, there are obvious and currently discussed
interoperability issues regarding the null terminator.

It should definitely get a slice syntax, since that will likely be the
most common operation on a string.
I would also like to support a notion of static sizing, but with UTF-8
even that's not always possible.

I reckon a string should be an object, and potentially be convertible
to/from a vector.  But trying to treat it like a vector will just lead
to surprising semantics for some.  But that's just my opinion.


On Mon, Apr 23, 2012 at 6:10 PM, Graydon Hoare <graydon at mozilla.com> wrote:
> On 12-04-23 12:58 PM, Rick Richardson wrote:
>
>> My line of thinking is this:
>> If you have an array of four Ints, the type of the array is 4 Ints.
>> It's incompatible with an array that is 5 ints without an adaptor.
>> Since [] indicates a vector, and a vector in Rust has both a length
>> and a type, Why not make the size of the vector the first of two
>> parameters in the []?
>>
>> e.g.     [N,T]
>>
>> or, for unspecified length:  [_,T]  (possibly sugared to [T])
>
> All versions of this syntax that work with the bound-inside-the-brackets
> need to have something to say for the 'str' type, which has no brackets.
> That's the problem.
>
> -Graydon
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev


More information about the Rust-dev mailing list