I'm trying to understand how to translate Java arrays into Rust.
Why is mutability different for owned and managed vectors? The
following program compiles and prints 42 when run:
fn main() {
let mut v: ~[i32] = ~[0, 0];
v[0] = 42;
let s = i32::to_str(v[0], 10);
io::println(s);
return;
}
However, the following program won't compile:
fn main() {
let mut v: @[i32] = @[0, 0];
v[0] = 42;
let s = i32::to_str(v[0], 10);
io::println(s);
return;
}
This compiles, however:
fn main() {
let mut v: @[mut i32] = @[mut 0, 0];
v[0] = 42;
let s = i32::to_str(v[0], 10);
io::println(s);
return;
}
- -
How is one supposed to implement growable buffers?
Can Rust vectors grow in-place?
http://dl.rust-lang.org/doc/0.4/core/at_vec.html#function-capacity
suggests they can. How does one append to a vector in-place? What's
the buffer growth strategy?
On the other hand, if vectors can't grow in-place and one needs to
explicitly allocate a new vector and copy the contents of the old
vector over, what's the right way to allocate a long (garbage-filled
or zero-filled) vector without putting a long series of zeros and, as
in the source code? That is, how do I say "give me a zero-filled
vector of length 1024"?
- -
What's the Rust equivalent of System.arrayCopy() for efficiently
copying a range of elements from a vector to another?
- -
Can a vector of object references have any empty slots? Or do empty
slots need to have some kind of dummy objects in them to avoid null
pointers?
--
Henri Sivonen
[email protected]
http://hsivonen.iki.fi/
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev