Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.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 Can';看不到枚举值_Rust - Fatal编程技术网

Rust Can';看不到枚举值

Rust Can';看不到枚举值,rust,Rust,我正在尝试重新创建在std::io中执行错误处理的方式。我的代码基于文章 我的问题是,我将代码放在一个单独的mod中,现在我看不到要返回的枚举值。代码示例: mod error { use std::str::SendStr; pub type ProgramResult<T> = Result<T, ProgramError>; #[deriving(Show)] pub struct ProgramError { k

我正在尝试重新创建在
std::io
中执行错误处理的方式。我的代码基于文章

我的问题是,我将代码放在一个单独的
mod
中,现在我看不到要返回的枚举值。代码示例:

mod error {
    use std::str::SendStr;

    pub type ProgramResult<T> = Result<T, ProgramError>;

    #[deriving(Show)]
    pub struct ProgramError {
        kind: ProgramErrorKind,
        message: SendStr
    }

    /// The kinds of errors that can happen in our program.
    /// We'll be able to pattern match against these.
    #[deriving(Show)]
    pub enum ProgramErrorKind {
        Configuration
    }

    impl ProgramError {
        pub fn new<T: IntoMaybeOwned<'static>>(msg: T, kind: ProgramErrorKind) -> ProgramError {
            ProgramError {
                kind: kind,
                message: msg.into_maybe_owned()
            }
        }
    }
}
mod错误{
使用std::str::SendStr;
发布类型ProgramResult=结果;
#[导出(显示)]
发布结构程序错误{
种类:程序错误种类,
信息:SendStr
}
///我们的程序中可能发生的各种错误。
///我们将能够对这些进行模式匹配。
#[导出(显示)]
发布枚举程序错误种类{
配置
}
impl程序错误{

pub fn new在尝试引用
enum
类型时是否使用模块解析运算符?例如,下面是一个工作正常的示例:

mod error {
    #[deriving(Show)]
    pub enum ProgramErrorKind {
        Configuration,
        SomethingElse
    }
}

fn main() {
    // You can import them locally with 'use'
    use error::Configuration;

    let err = Configuration;

    // Alternatively, use '::' directly
    let res = match err {
        error::Configuration => "Config error!",
        error::SomethingElse => "I have no idea.",
    };
    println!("Error type: {}", res);
}

您是否执行了
use error::Configuration
?我认为导入ProgramErrorKind就足够了?@lapinrigolo
use error:{ProgramErrorKind,Configuration,SomethingElse};
就是您想要的。