On 12-07-13 1:44 PM, Michael Sullivan wrote:

An example of some code that could use it:
// Some code that could use that, then:
fn seq_range(uint lo, uint hi) -> @[uint] {
     do construct() |push| {
         for range(lo, hi) |i| {
             push(i);
         }
     }
}

The critical feature of this interface is that the actual vector is
not exposed until after it has been constructed. The construct
function will be implemented unsafely, but it is a safe interface. (If
use of the vector needs to be interleaved with creation of it, then
you probably need to use `avec`)

One of the big advantages of this general interface is that it works
well for lots of different types; this would work for basically any
"sequence" type we have in rust. There are ways it can be extended,
too, like having construct take a size hint.

Yeah, I think the general shape of the interface is good. The size-unhinted version can (and perhaps should?) be layered on top of the size-hinted version; also I think you will want to pass the current index into the callback.

(also: "construct"? hm, maybe build or alloc? init?)

-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to