首页 > 代码库 > Rust d

Rust d

extern crate libc;

use libc::c_int;
enum Hello{
    Req = 1i,
    Pub = 2i,

}

impl Hello{

    fn to_raw(&self) -> c_int{
        *self as c_int
    }
}

fn main() {
    println!("Hello, world!")
    println!("{}", Hello::Pub.to_raw());
}



<!-- lang: shell -->
<anon>:16:9: 16:14 error: cannot move out of dereference of `&`-pointer
<anon>:16         *self as c_int
                              ^~~~~
error: aborting due to previous error
  playpen: application terminated with error code 101

今天编译 nanomsg ,出错了,喔喔。

42<> 21:30:12 在群里解释到:
最新版的Copy Trait变成opt-in了,必须手动给类型实现Copy
不然*self这种会报错

好吧, 尝试了一下 :你可以#[deriving(Copy)]
然后就没问题了
在此输入图片描述

Rust d