I can write this:
struct Points {xs:~[uint], ys:~[uint]}
fn main () {
let mut ps = Points{xs:~[1u], ys:~[1u]};
...
}
But I cannot write that:
struct Points<T> {xs:~[T], ys:~[T]}
fn main () {
let mut ps = Points<uint>{xs:~[1u], ys:~[1u]};
...
}
In the second case, I get the error:
sparse_array.rs:106:31: 106:32 error: expected one of `; }` but found `:`
sparse_array.rs:106 let mut ps = Points<uint>{xs:~[1u], ys:~[1u]};
^
Sorry to bother you with that, I find myself unable to find the right syntactic
schema (and could not find any example in any doc online). I'm blocked, stupidly.
spir@ospir:~$ rust -v
rust 0.8
host: x86_64-unknown-linux-gnu
Also, I have a general problem with writing struct instances with the type
apart; meaning, without any type param, I get the same error:
struct Points {xs:~[uint], ys:~[uint]}
fn main () {
let mut ps : Points = {xs:~[1], ys:~[1]};
...
}
==>
parse_array.rs:106:28: 106:29 error: expected one of `; }` but found `:`
sparse_array.rs:106 let mut ps : Points = {xs:~[1], ys:~[1]};
^
More generally, I don't know why there are 2 syntactic schemas to define vars. I
would be happy with the latter alone (despite the additional pair of spaces)
since it is more coherent and more general in allowing temporalily uninitialised
declarations.
Denis
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev