Last active
June 23, 2020 15:57
-
-
Save elbart/cba0297e128bf36e735fea82e9f473ff to your computer and use it in GitHub Desktop.
rs playground data structures
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
use std::cell::RefCell; | |
#[derive(Debug)] | |
struct YakeTarget<'a> { | |
pub name: String, | |
pub dependencies: Option<Vec<&'a YakeTarget<'a>>>, | |
} | |
#[derive(Debug)] | |
struct Yake<'a> { | |
pub targets: Vec<YakeTarget<'a>> | |
} | |
impl<'a> Yake<'a> { | |
fn new(targets: Vec<YakeTarget<'a>>) -> Self { | |
Yake { | |
targets: targets | |
} | |
} | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
#[test] | |
fn base_layout() { | |
let t1 = YakeTarget { | |
name: "psql".into(), | |
dependencies: None | |
}; | |
let t2 = YakeTarget { | |
name: "docker".into(), | |
dependencies: Some(vec![&t1]) | |
}; | |
let targets = vec![t1, t2]; | |
let y = Yake::new(targets); | |
println!("{:#?}", y.targets); | |
} | |
} |
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
error[E0505]: cannot move out of `t1` because it is borrowed | |
--> src/lib.rs:38:28 | |
| | |
35 | dependencies: Some(vec![&t1]) | |
| --- borrow of `t1` occurs here | |
... | |
38 | let targets = vec![t1, t2]; | |
| ^^ -- borrow later used here | |
| | | |
| move out of `t1` occurs here | |
error: aborting due to previous error; 1 warning emitted | |
For more information about this error, try `rustc --explain E0505`. | |
error: could not compile `tryout`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment