Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Why do all variables need to be of a type that implements Sized?
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
🏷️ rust_feed