Graydon, Firstly I understand you know a lot more about this than I do, and I have read and appreciated everything that you wrote.
On 6 September 2012 22:42, Graydon Hoare <[email protected]> wrote: > Right. So then, typical use API-use would be &str, access to the bytes > would be double-indirect, and we'd be unable to do any constant-string or > substring optimizations, correct? > > OK then, that scheme would suck. So how about a slightly different scheme where a str is (internally) a tuple of (pointer-to-char-data-on-the-unique-heap, start-index, end-index) - i.e. 3 words - pretty cheap to shallow copy - right?. A str would be a non-implicitly copyable type. A ~str/@str/&str would be the same as any other ~/@/& pointers (this is what I am aiming for). A constant string would be a &static/str, and start-index and end-index would be the start and end of the character data (which is stored in constant memory). A substring (AKA slice) would point to the same character data as its parent string, but have different start/end indexes. I believe that the region system would keep a substring's character data alive for as long as its parent lives (right?). Idiomatic usage would be to pass most string parameters as &str. Apart from fixed-length strings, which could perhaps be treated specially, is this a reasonable way to accomplish the objective of making string pointers the same as other pointers (apart from vector pointers, which in are in another kettle of fish). Thanks Gareth
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
