Comment

Comment by kibwen

> Want to have a data structure of variable size (eg a struct with an Vector in it)? You can't do that, structs have to be fixed size.

I'm unclear what you mean here, because Vecs in Rust do have a fixed size. You can see this by using std::mem::size_of on a Vec: for any type, a Vec is three words in size. You can see this documented in the stdlib documentation for Vecs: https://doc.rust-lang.org/std/vec/struct.Vec.html#guarantees

"Vec is and always will be a (pointer, capacity, length) triplet. No more, no less."

So what you're asking for, a Vec in a struct, works just fine:

    struct Foo {
        v: Vec<i32>
    }

    let foo = Foo { v: vec![1,2,3] };
Can you elaborate on what trouble you're having?
parent kibwen 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton