Reputation: 2154
I've noticed some rust functions return references to empty data structures. I'm trying to get a sense for where references of these types point to in memory and why one would want to return a reference to an empty data structure in the first place. For instance where does &()
point to in memory for the following Rust programs?
struct EmptyType;
impl Deref for EmptyType {
type Target = ();
fn deref(&self) -> &Self::Target {
// where does this point to?
&()
}
}
fn main() {
// where does &a point to
let a = ();
}
Upvotes: 0
Views: 49
Reputation: 70900
Nothing is guaranteed, but currently the first is pointing somewhere in the binary address space and the second somewhere on the stack.
Upvotes: 1