Last active
December 19, 2015 23:29
-
-
Save eevee/6034960 to your computer and use it in GitHub Desktop.
how do i make this work damn
This file contains 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
terminal-example.rs:35:17: 35:21 error: borrowed value does not live long enough | |
terminal-example.rs:35 let canvas = term.create_canvas(); | |
^~~~ | |
terminal-example.rs:33:39: 40:1 note: borrowed pointer must be valid for the lifetime &'r as defined on the block at 33:39... | |
terminal-example.rs:33 fn get_app_state<'r>() -> AppState<'r> { | |
terminal-example.rs:34 let term = Terminal::new(); | |
terminal-example.rs:35 let canvas = term.create_canvas(); | |
terminal-example.rs:36 return AppState{ | |
terminal-example.rs:37 term: term, | |
terminal-example.rs:38 canvas: canvas, | |
... | |
terminal-example.rs:33:39: 40:1 note: ...but borrowed value is only valid for the block at 33:39 | |
terminal-example.rs:33 fn get_app_state<'r>() -> AppState<'r> { | |
terminal-example.rs:34 let term = Terminal::new(); | |
terminal-example.rs:35 let canvas = term.create_canvas(); | |
terminal-example.rs:36 return AppState{ | |
terminal-example.rs:37 term: term, | |
terminal-example.rs:38 canvas: canvas, | |
... | |
error: aborting due to previous error |
This file contains 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
struct Terminal { | |
output_fd: uint, | |
} | |
impl Terminal { | |
fn new() -> Terminal { | |
return Terminal{ output_fd: 1 }; | |
} | |
fn create_canvas<'r>(&'r self) -> Canvas<'r> { | |
return Canvas{ | |
term: self, | |
}; | |
} | |
} | |
struct Canvas<'self> { | |
term: &'self Terminal, | |
} | |
struct AppState<'self> { | |
term: Terminal, | |
canvas: Canvas<'self>, | |
} | |
fn main() { | |
let app = get_app_state(); | |
} | |
fn get_app_state<'r>() -> AppState<'r> { | |
let term = Terminal::new(); | |
let canvas = term.create_canvas(); | |
return AppState{ | |
term: term, | |
canvas: canvas, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment