Created
March 22, 2014 19:57
-
-
Save TyOverby/9713305 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
| $ rustc image.rs | |
| image.rs:42:9: 43:6 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements | |
| image.rs:42 self.pixels.as_mut_slice() | |
| image.rs:43 } | |
| image.rs:42:9: 42:20 note: first, the lifetime cannot outlive the expression at 42:8... | |
| image.rs:42 self.pixels.as_mut_slice() | |
| ^~~~~~~~~~~ | |
| image.rs:42:9: 42:20 note: ...so that automatically reference is valid at the time of borrow | |
| image.rs:42 self.pixels.as_mut_slice() | |
| ^~~~~~~~~~~ | |
| image.rs:42:9: 43:6 note: but, the lifetime must be valid for the method call at 42:8... | |
| image.rs:42 self.pixels.as_mut_slice() | |
| image.rs:43 } | |
| image.rs:42:9: 42:20 note: ...so that method receiver is valid for the method call | |
| image.rs:42 self.pixels.as_mut_slice() | |
| ^~~~~~~~~~~ | |
| image.rs:40:1: 44:2 error: failed to find an implementation of trait std::clone::Clone for Color | |
| image.rs:40 impl <Color> DirectView<Color> for Image<Color> { | |
| image.rs:41 fn scanline(&mut self, y: uint) -> &mut [Color] { | |
| image.rs:42 self.pixels.as_mut_slice() | |
| image.rs:43 } | |
| image.rs:44 } | |
| task 'rustc' failed at 'explicit failure', /build/buildd/rust-0.9-0.9/src/libsyntax/diagnostic.rs:41 | |
| task '<main>' failed at 'explicit failure', /build/buildd/rust-0.9-0.9/src/librustc/lib.rs:453 |
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
| use std::clone::Clone; | |
| use std::default::Default; | |
| use std::vec; | |
| trait View<Color> { | |
| fn width(&self) -> uint; | |
| fn height(&self) -> uint; | |
| fn get(&self, x: uint, y: uint) -> Color; | |
| } | |
| trait WritableView<Color> : View<Color> { | |
| fn set(&mut self, x: uint, y: uint, color: Color); | |
| } | |
| trait DirectView<Color> : View<Color> { | |
| fn scanline(&mut self, y: uint) -> &mut [Color]; | |
| } | |
| struct Image<Color> { | |
| priv width: uint, | |
| priv height: uint, | |
| priv pixels: ~[Color] | |
| } | |
| impl <Color: Clone> View<Color> for Image<Color> { | |
| fn width(&self) -> uint { self.width } | |
| fn height(&self) -> uint { self.height } | |
| fn get(&self, x: uint, y: uint) -> Color { | |
| self.pixels[self.width * y + x].clone() | |
| } | |
| } | |
| impl <Color: Clone> WritableView<Color> for Image<Color> { | |
| fn set(&mut self, x: uint, y: uint, color: Color) { | |
| self.pixels[self.width * y + x] = color; | |
| } | |
| } | |
| impl <Color> DirectView<Color> for Image<Color> { | |
| fn scanline(&mut self, y: uint) -> &mut [Color] { | |
| self.pixels.as_mut_slice() | |
| } | |
| } | |
| impl <Color: Default> Image<Color> { | |
| fn with_default(width: uint, height: uint) -> Image<Color> { | |
| Image { | |
| width: width, | |
| height: height, | |
| pixels: vec::from_fn(width * height, |_| {Default::default()}) | |
| } | |
| } | |
| } | |
| impl <Color: Clone> Image<Color> { | |
| fn with_copy(width: uint, height: uint, color: Color) -> Image<Color> { | |
| Image { | |
| width: width, | |
| height: height, | |
| pixels: vec::from_elem(width * height, color) | |
| } | |
| } | |
| } | |
| fn main() { | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment