Why do all variables need to be of a type that implements Sized?

⚓ Rust    📅 2025-07-09    👤 surdeus    👁️ 3      

surdeus

Probably a silly question but I don't have much background on this area.

I've noticed that str isn't ever in the code directly, or as type annotation. Only &str, Box<str>, Arc<str> etc.

So it seems that the reason which I got from the compiler, by doing:

let a = String::from("h");
let b = a.into_boxed_str();
let c = *b;
}

Is that all variables need to be sized (including function arguments etc.)

The basic question is: why do all variables need to be sized? Does it mean as well that one never sees the type [T] (which I guess str is that i.e [u8]) but only arrays which are [T, N]?

In a way, one can still have them unsized on the Heap since Box<str> is allowed, but somehow not elsewhere.

1 post - 1 participant

Read full topic

🏷️ rust_feed