Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rust 尝试“使用”枚举将导致“使用”;“未解决的进口”;_Rust - Fatal编程技术网

Rust 尝试“使用”枚举将导致“使用”;“未解决的进口”;

Rust 尝试“使用”枚举将导致“使用”;“未解决的进口”;,rust,Rust,: 然而,如果你在链接到的在线网站上运行这个,它就可以正常工作。我不明白为什么这对我不起作用。我需要最新的(夜间)防锈剂吗 rustc--version显示我已经有了0.12.0-dev版本。是的,你需要每晚一次。如果我没记错的话,名称空间枚举是在0.12发布之后引入的 总的来说,除非你有很好的理由不这样做,否则你应该睡夜觉。这是大多数人使用的。如果你不这样做,你将与谷物作斗争——大多数活跃的库会随着夜间发布而定期更新。是的,你需要夜间更新。如果我没记错的话,名称空间枚举是在0.12发布之后引入

:

然而,如果你在链接到的在线网站上运行这个,它就可以正常工作。我不明白为什么这对我不起作用。我需要最新的(夜间)防锈剂吗


rustc--version
显示我已经有了0.12.0-dev版本。

是的,你需要每晚一次。如果我没记错的话,名称空间枚举是在0.12发布之后引入的


总的来说,除非你有很好的理由不这样做,否则你应该睡夜觉。这是大多数人使用的。如果你不这样做,你将与谷物作斗争——大多数活跃的库会随着夜间发布而定期更新。

是的,你需要夜间更新。如果我没记错的话,名称空间枚举是在0.12发布之后引入的


总的来说,除非你有很好的理由不这样做,否则你应该睡夜觉。这是大多数人使用的。如果你不这样做,你将与谷物作斗争——大多数活跃的库会随着夜间发布而定期更新。

是的,你需要夜间更新。如果我没记错的话,名称空间枚举是在0.12发布之后引入的


总的来说,除非你有很好的理由不这样做,否则你应该睡夜觉。这是大多数人使用的。如果你不这样做,你将与谷物作斗争——大多数活跃的库会随着夜间发布而定期更新。

是的,你需要夜间更新。如果我没记错的话,名称空间枚举是在0.12发布之后引入的


总的来说,除非你有很好的理由不这样做,否则你应该睡夜觉。这是大多数人使用的。如果你不这样做,你将与谷物作斗争——大多数活跃的库会随着《夜间睡》的发布而定期更新。

还要记住,一般情况下,不是
使用列表::…
,而是
使用自组::列表::…
,对于use语句,使用绝对路径。还要记住,一般情况不是
使用列表::…
,而是
使用self::List::…
,对于use语句,使用绝对路径。还要记住,一般情况不是
使用列表::…
,而是
使用self::List::…
,对于use语句,使用绝对路径。还要记住,一般情况下不是
使用列表::…
,而是
使用self::List::…
,对于use语句,使用绝对路径。
// Allow Cons and Nil to be referred to without namespacing
use List::{Cons, Nil};

// A linked list node, which can take on any of these two variants
enum List {
    // Cons: Tuple struct that wraps an element and a pointer to the next node
    Cons(uint, Box<List>),
    // Nil: A node that signifies the end of the linked list
    Nil,
}

// Methods can be attached to an enum
impl List {
    // Create an empty list
    fn new() -> List {
        // `Nil` has type `List`
        Nil
    }

    // Consume a list, and return the same list with a new element at its front
    fn prepend(self, elem: uint) -> List {
        // `Cons` also has type List
        Cons(elem, box self)
    }

    // Return the length of the list
    fn len(&self) -> uint {
        // `self` has to be matched, because the behavior of this method
        // depends on the variant of `self`
        // `self` has type `&List`, and `*self` has type `List`, matching on a
        // concrete type `T` is preferred over a match on a reference `&T`
        match *self {
            // Can't take ownership of the tail, because `self` is borrowed;
            // instead take a reference to the tail
            Cons(_, ref tail) => 1 + tail.len(),
            // Base Case: An empty list has zero length
            Nil => 0
        }
    }

    // Return representation of the list as a (heap allocated) string
    fn stringify(&self) -> String {
        match *self {
            Cons(head, ref tail) => {
                // `format!` is similar to `print!`, but returns a heap
                // allocated string instead of printing to the console
                format!("{}, {}", head, tail.stringify())
            },
            Nil => {
                format!("Nil")
            },
        }
    }
}

fn main() {
    // Create an empty linked list
    let mut list = List::new();

    // Append some elements
    list = list.prepend(1);
    list = list.prepend(2);
    list = list.prepend(3);

    // Show the final state of the list
    println!("linked list has length: {}", list.len());
    println!("{}", list.stringify());
}
test.rs:2:12: 2:16 error: unresolved import `List::Cons`. Cannot import from a trait or type implementation
test.rs:2 use List::{Cons, Nil};
                     ^~~~
test.rs:2:18: 2:21 error: unresolved import `List::Nil`. Cannot import from a trait or type implementation
test.rs:2 use List::{Cons, Nil};
                           ^~~
error: aborting due to 2 previous errors