Hi,
Some random questions based on playing around with Rust for a few weeks.
1. Do mutable variant types allocated in stack always occupy a fixed space
(the size of the largest possibly value) ?
I guess it would have to be so, just wondering if there might be some
other magic going on.
That is, e.g. what happens with the following piece of code:
pub fn test() -> Option<float> {
let mut r = None;
let s = 10; // Just some value presumably allocated
after r in stack
r = Some(10.3f);
r
}
2. How to allocate a mutable managed vector dynamically?
I can create an owned vector with: let a = vec::from_elem(..);
I can create a managed vector with: let a = at_vec::from_elem(..);
But I can't seem to figure out how to create a mutable managed vector
(apart from using a literal).
I tried:
let mut a = at_vec::from_elem(...);
a[0] = 1.1;
But the compiler didn't seem to like it.
3. Can you return stack allocated literal vectors (either using the create
directly in calling stack semantic or as a copied value type)?
I tried:
fn newInStack() -> [int] { [1, 2] }
But was hit with a compile error.
4. Can you control where a result gets built from the calling side? Making
several copies of a simple
constructor function to be able to allocate things in different places
seems a bit silly.
fn newInStack() -> Foo { Foo(1,2) }
fn newOwned() -> ~Foo { ~Foo(1,2) }
fn newManaged() -> @Foo { @Foo(1,2) }
I especially was wondering about this in the context of 'vec' and
'at_vec' and trying (and failing) to create
a mutable managed array; and left wondering if I'd need to create a new
module 'at_mut_vec'. (And somewhere in
the back of my head wondering, if all these modules would really be
needed or if this is an indication of a
problem with expressiveness of the language in such cases).
Thanks,
Sami
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev