我正在尝试使用RefCell和创建图形Rc.我想在一个带有字符串标签的循环中创建100个节点.这是图表表示:
struct Node {
datum: &'static str,
edges: Vec<Rc<RefCell<Node>>>,
}
impl Node {
fn new(datum: &'static str) -> Rc<RefCell<Node>> {
Rc::new(RefCell::new(Node {
datum: datum,
edges: Vec::new(),
}))
}
}
Run Code Online (Sandbox Code Playgroud)
这是我写的用于创建节点的循环:
for i in 0..100 {
let a = Node::new(concat!("A", i));
let b = Node::new(concat!("A", i + 1));
{
let mut mut_root = a.borrow_mut();
mut_root.edges.push(b.clone());
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
error: expected a literal
--> src/main.rs:17:40
|
17 | let a = Node::new(concat!("A", i));
| ^
error: expected a …Run Code Online (Sandbox Code Playgroud) rust ×1