我正在尝试编写我的第一个 Rust 程序。我想在屏幕上打印一棵简单的树,但我无法访问value
属性,它说
错误 1 尝试访问
value
type 上的字段Node
,但找不到具有该名称的字段 c:\users\zhukovskiy\documents\visual studio 2013\Projects\rust_application1\rust_application1\src\main.rs 21 20 rust_application1
use std::io;
enum Node {
Branch { value: i32, next: *const Node },
Leaf { value: i32 }
}
fn main() {
let leaf = Node::Leaf { value: 15 };
let branch = Node::Branch { value: 10, next: &leaf };
let root = Node::Branch { value: 50, next: &branch };
let current = root;
loop {
match current {
Node::Branch => { println!("{}", current.value); current = current.next; },
Node::Leaf => { println!("{}", current.value); break; },
}
}
}