2014-12-02 08:20:48 -06:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
|
|
|
//! Error handling utilities. WIP.
|
|
|
|
|
2015-02-26 23:00:43 -06:00
|
|
|
use std::error::Error;
|
2014-12-02 08:20:48 -06:00
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
pub type CliError = Box<Error + 'static>;
|
|
|
|
pub type CliResult<T> = Result<T, CliError>;
|
|
|
|
|
|
|
|
pub type CommandError = Box<Error + 'static>;
|
|
|
|
pub type CommandResult<T> = Result<T, CommandError>;
|
|
|
|
|
2015-02-26 23:00:43 -06:00
|
|
|
pub fn err(s: &str) -> CliError {
|
2015-03-19 18:37:34 -05:00
|
|
|
#[derive(Debug)]
|
2015-02-26 23:00:43 -06:00
|
|
|
struct E(String);
|
2014-12-02 08:20:48 -06:00
|
|
|
|
2015-02-26 23:00:43 -06:00
|
|
|
impl Error for E {
|
|
|
|
fn description(&self) -> &str { &self.0 }
|
2014-12-02 08:20:48 -06:00
|
|
|
}
|
2015-02-26 23:00:43 -06:00
|
|
|
impl fmt::Display for E {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
self.0.fmt(f)
|
|
|
|
}
|
2014-12-02 08:20:48 -06:00
|
|
|
}
|
|
|
|
|
2015-02-26 23:00:43 -06:00
|
|
|
Box::new(E(s.to_string()))
|
2014-12-02 08:20:48 -06:00
|
|
|
}
|