Last active
August 29, 2015 14:09
-
-
Save gchp/5c5861888f2a345fa0b1 to your computer and use it in GitHub Desktop.
Dereference error
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
type Link = Option<Box<Line>>; | |
struct Cursor { | |
line: Link, | |
} | |
struct Line { | |
next: Link, | |
value: String, | |
} | |
struct Buffer { | |
head: Link, | |
cursor: Cursor, | |
} | |
impl Buffer { | |
pub fn set_cursor(&mut self) { | |
self.cursor.line = self.head; | |
} | |
pub fn do_something_else(&self) {} | |
} | |
fn main() { | |
let mut buffer = Buffer { | |
head: None, | |
cursor: Cursor { line: None } | |
}; | |
buffer.set_cursor(); | |
buffer.do_something_else(); | |
} | |
/* | |
This gives an error: | |
$ rustc main.rs | |
error.rs:19:28: 19:32 error: cannot move out of dereference of `&mut`-pointer | |
error.rs:19 self.cursor.line = self.head; | |
^~~~ | |
error: aborting due to previous error | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment