Created
November 17, 2013 02:17
-
-
Save DaGenix/7508248 to your computer and use it in GitHub Desktop.
Lifetime thing
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
trait GetBuffer<'self> { | |
fn get(&self) -> &'self [u8]; | |
} | |
// This works | |
struct Buff1<'self> { | |
b: &'self [u8] | |
} | |
impl <'self> GetBuffer<'self> for Buff1<'self> { | |
fn get(&self) -> &'self [u8] { self.b } | |
} | |
// This doesn't | |
struct Buff2 { | |
b: ~[u8] | |
} | |
impl <'self> GetBuffer<'self> for Buff2 { | |
fn get(&self) -> &'self [u8] { self.b.slice(0, 1) } | |
} | |
fn main() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error:
' failed at 'explicit failure', /home/enix/code/rust/src/librustc/lib.rs:397testrp.rs:18:32: 18:52 error: cannot infer an appropriate lifetime due to conflicting requirements
testrp.rs:18 fn get(&self) -> &'self [u8] { self.b.slice(0, 1) }
^~~~~~~~~~~~~~~~~~~~
testrp.rs:18:32: 18:38 note: first, the lifetime cannot outlive the expression at 18:32...
testrp.rs:18 fn get(&self) -> &'self [u8] { self.b.slice(0, 1) }
^~~~~~
testrp.rs:18:32: 18:38 note: ...due to the following expression
testrp.rs:18 fn get(&self) -> &'self [u8] { self.b.slice(0, 1) }
^~~~~~
testrp.rs:18:32: 18:52 note: but, the lifetime must be valid for the method call at 18:32...
testrp.rs:18 fn get(&self) -> &'self [u8] { self.b.slice(0, 1) }
^~~~~~~~~~~~~~~~~~~~
testrp.rs:18:32: 18:38 note: ...due to the following expression
testrp.rs:18 fn get(&self) -> &'self [u8] { self.b.slice(0, 1) }
^~~~~~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /home/enix/code/rust/src/libsyntax/diagnostic.rs:101
task '