This code fails if I call anything after the steal_ownership_fuction() function.
Can you guys tell me why? Why does that simple print function break things? I am super new to rust, sorry if its a odd question.
Compiler message:
note: this function takes ownership of the receiver self
, which moves flight_path_segment
#[derive(Debug)]
struct WayPoint<T> {
name: String,
latitude: T,
longitude: T,
}
impl Segment {
fn new(start: WayPoint<f64>, end: WayPoint<f64>) -> Self {
Self {
start,
end
}
}
fn steal_ownership_fuction(self) -> String {
"Test return".to_string()
}
}
#[derive(Debug)]
struct Segment {
start: WayPoint<f64>,
end: WayPoint<f64>
}
fn main() {
let way_point_fhl = WayPoint {
name: "FHL".to_string(),
latitude: 36.0036,
longitude: -121.2313,
};
let way_point_bonny_dune = WayPoint {
name: "Bonny Dune".to_string(),
latitude: 37.04167,
longitude: -122.14944,
};
//println!("{} {} {}", test.name, test.longitude, test.latitude);
let flight_path_segment = Segment::new(way_point_fhl, way_point_bonny_dune);
// {:?} dump full object if it defines Debug
println!("{:?}", flight_path_segment);
println!("{}", flight_path_segment.steal_ownership_fuction());
//Second call to same function breaks code
println!("{}", flight_path_segment.steal_ownership_fuction());
}