I am building a struct called DATAMAP which is designed to hold a vector of TCPStreams.
After I declare the struct, I proceed to instantiate a global const reference to it.
The issue I am having is that the global const pointer address seems to be changing from one method call to the next. Note there are no assignments, just referenced usage. I am simply trying to use the struct and access my Vec called 'connections'. Below are the declarations:
//DECLARATIONS
struct datamap {
connections: Vec<TcpStream>,
}
impl datamap {
fn push(&mut self, conn: TcpStream) {
println!("Adding connection to vec");
self.connections.push(conn);
}
fn len(self) -> usize {
return self.connections.len();
}
}
impl fmt::Pointer for datamap {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:p}", self as *const datamap)
}
}
// CREATE A STRUCT - Note we are global scope here
const app: datamap = datamap {
connections: Vec::new(),
};
// MAIN
fn main() {
println!("The address of the app struct is {:p}", app);
some_other_method(); // call another scope method to see issue
}
fn some_other_method() {
println!("The address of the app struct is {:p}", app);
}
The output will end up like:
The address of the app struct is 0x7ffee8613180
The address of the app struct is 0x7ffee8612fb8
How is the const getting a new address?