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就足够了?@lapinrigolouse error:{ProgramErrorKind,Configuration,SomethingElse};
就是您想要的。