Created
November 22, 2014 11:19
-
-
Save denisdefreyne/5723bc3a950558e06b74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate core; | |
struct Point { | |
t: f32, | |
l: f32, | |
} | |
impl core::fmt::Show for Point { | |
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { | |
write!(f, "Point(left={}, top={})", self.l, self.t) | |
} | |
} | |
pub fn main() { | |
// Create points | |
let mut points: Vec<Point> = Vec::new(); | |
points.push(Point{t: 10f32, l: 10f32}); | |
println!("points: {}", points); | |
// Mutate points | |
for &mut point in points.iter() { | |
point.t += 10f32; | |
} | |
println!("points: {}", points); | |
} | |
// Actual output: | |
// points: [Point(left=10, top=10)] | |
// points: [Point(left=10, top=10)] | |
// | |
// Expected output: | |
// points: [Point(left=10, top=10)] | |
// points: [Point(left=10, top=20)] <- difference is here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment