issue-3447.rs 910 字节
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

11
struct list<'self, T> {
12 13
    element: &'self T,
    next: Option<@mut list<'self, T>>
T
Tim Chevalier 已提交
14 15
}

16 17
impl<'self, T> list<'self, T>{
    pub fn addEnd(&mut self, element: &'self T) {
T
Tim Chevalier 已提交
18 19
        let newList = list {
            element: element,
20
            next: None
T
Tim Chevalier 已提交
21 22
        };

23
        self.next = Some(@mut newList);
T
Tim Chevalier 已提交
24 25 26
    }
}

27
pub fn main() {
T
Tim Chevalier 已提交
28
    let s = @"str";
29
    let ls = list {
T
Tim Chevalier 已提交
30
        element: &s,
31
        next: None
T
Tim Chevalier 已提交
32
    };
33
    println(*ls.element);
T
Tim Chevalier 已提交
34
}