Skip to content

Instantly share code, notes, and snippets.

@crumblingstatue
Created January 7, 2015 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crumblingstatue/278224e88b135a6dd985 to your computer and use it in GitHub Desktop.
Save crumblingstatue/278224e88b135a6dd985 to your computer and use it in GitHub Desktop.
/// ```rust
/// use crusty_chip::{ DISPLAY_WIDTH, VirtualMachine };
/// // Dump the pixels to stdout
/// fn dump_pixels(pixels: &[u8]) {
/// for (i, px) in pixels.iter().enumerate() {
/// match *px {
/// 0 => print!(" "),
/// _ => print!("#")
/// }
/// if i % DISPLAY_WIDTH == 0 {
/// print!("\n");
/// }
/// }
/// }
/// let mut ch8 = VirtualMachine::new(&mut dump_pixels);
/// // ...
/// ```
---- DrawCallback_0 stdout ----
<anon>:19:48: 19:59 error: borrowed value does not live long enough
<anon>:19 let mut ch8 = VirtualMachine::new(&mut dump_pixels);
^~~~~~~~~~~
<anon>:5:11: 21:2 note: reference must be valid for the block at 5:10...
<anon>:5 fn main() {
<anon>:6 use crusty_chip::{ DISPLAY_WIDTH, VirtualMachine };
<anon>:7 // Dump the pixels to stdout
<anon>:8 fn dump_pixels(pixels: &[u8]) {
<anon>:9 for (i, px) in pixels.iter().enumerate() {
<anon>:10 match *px {
...
<anon>:19:9: 19:60 note: ...but borrowed value is only valid for the statement at 19:8
<anon>:19 let mut ch8 = VirtualMachine::new(&mut dump_pixels);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:19:9: 19:60 help: consider using a `let` binding to increase its lifetime
<anon>:19 let mut ch8 = VirtualMachine::new(&mut dump_pixels);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
thread 'DrawCallback_0' panicked at 'Box<Any>', /build/rust-git/src/rust/src/libsyntax/diagnostic.rs:144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment