Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Format code using 'cargo fmt' #280

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
extern crate error_chain;

pub mod inner {
error_chain!{}
error_chain! {}
}

#[cfg(feature = "a_feature")]
pub mod feature {
error_chain!{}
error_chain! {}
}

error_chain! {
Expand Down
10 changes: 4 additions & 6 deletions examples/chain_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ extern crate error_chain;
use std::fs::File;

mod errors {
use std::io;
use super::LaunchStage;
use std::io;

error_chain! {
foreign_links {
Expand Down Expand Up @@ -54,11 +54,9 @@ fn load_config(rel_path: &str) -> Result<()> {
/// Launch the service.
fn launch(rel_path: &str) -> Result<()> {
load_config(rel_path).map_err(|e| match e {
e @ Error(ErrorKind::ConfigLoad(_), _) => {
e.chain_err(|| LaunchStage::ConfigLoad)
}
e => e.chain_err(|| "Unknown failure"),
})
e @ Error(ErrorKind::ConfigLoad(_), _) => e.chain_err(|| LaunchStage::ConfigLoad),
e => e.chain_err(|| "Unknown failure"),
})
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate error_chain;

/// Inner module.
pub mod inner {
error_chain!{}
error_chain! {}
}

error_chain! {
Expand Down
10 changes: 4 additions & 6 deletions examples/quickstart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern crate error_chain;
// `error_chain!` creates.
mod errors {
// Create the Error, ErrorKind, ResultExt, and Result types
error_chain!{}
error_chain! {}
}

// This only gives access within this module. Make this `pub use errors::*;`
Expand Down Expand Up @@ -51,8 +51,8 @@ fn main() {
#[allow(dead_code)]
fn alternative_main() {
if let Err(ref e) = run() {
use std::io::Write;
use error_chain::ChainedError; // trait which holds `display_chain`
use error_chain::ChainedError;
use std::io::Write; // trait which holds `display_chain`
let stderr = &mut ::std::io::stderr();
let errmsg = "Error writing to stderr";

Expand All @@ -65,16 +65,14 @@ fn alternative_main() {
// set the `RUST_BACKTRACE` env variable to see a backtrace.
// quick_main!(run);


// Most functions will return the `Result` type, imported from the
// `errors` module. It is a typedef of the standard `Result` type
// for which the error type is always our own `Error`.
fn run() -> Result<()> {
use std::fs::File;

// This operation will fail
File::open("tretrete")
.chain_err(|| "unable to open tretrete file")?;
File::open("tretrete").chain_err(|| "unable to open tretrete file")?;

Ok(())
}
2 changes: 1 addition & 1 deletion src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod imp {
};
ENABLED.store(enabled as usize + 1, Ordering::SeqCst);
if !enabled {
return InternalBacktrace { backtrace: None }
return InternalBacktrace { backtrace: None };
}
}
1 => return InternalBacktrace { backtrace: None },
Expand Down
2 changes: 1 addition & 1 deletion src/example_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/// Another code generated by the macro.
pub mod inner {
error_chain!{}
error_chain! {}
}

error_chain! {
Expand Down
35 changes: 21 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@
//! [`BacktraceFrame`]: https://docs.rs/backtrace/0.3.2/backtrace/struct.BacktraceFrame.html

use std::error;
use std::iter::Iterator;
use std::fmt;
use std::iter::Iterator;

#[macro_use]
mod impl_error_chain_kind;
Expand All @@ -550,9 +550,9 @@ mod error_chain;
#[macro_use]
mod quick_main;
pub use quick_main::ExitCode;
mod backtrace;
#[cfg(feature = "example_generated")]
pub mod example_generated;
mod backtrace;
pub use backtrace::Backtrace;
#[doc(hidden)]
pub use backtrace::InternalBacktrace;
Expand Down Expand Up @@ -597,13 +597,16 @@ pub trait ChainedError: error::Error + Send + 'static {
type ErrorKind;

/// Constructs an error from a kind, and generates a backtrace.
fn from_kind(kind: Self::ErrorKind) -> Self where Self: Sized;
fn from_kind(kind: Self::ErrorKind) -> Self
where
Self: Sized;

/// Constructs a chained error from another error and a kind, and generates a backtrace.
fn with_chain<E, K>(error: E, kind: K) -> Self
where Self: Sized,
E: ::std::error::Error + Send + 'static,
K: Into<Self::ErrorKind>;
where
Self: Sized,
E: ::std::error::Error + Send + 'static,
K: Into<Self::ErrorKind>;

/// Returns the kind of the error.
fn kind(&self) -> &Self::ErrorKind;
Expand All @@ -624,27 +627,32 @@ pub trait ChainedError: error::Error + Send + 'static {

/// Extends the error chain with a new entry.
fn chain_err<F, EK>(self, error: F) -> Self
where F: FnOnce() -> EK,
EK: Into<Self::ErrorKind>;
where
F: FnOnce() -> EK,
EK: Into<Self::ErrorKind>;

/// Creates an error from its parts.
#[doc(hidden)]
fn new(kind: Self::ErrorKind, state: State) -> Self where Self: Sized;
fn new(kind: Self::ErrorKind, state: State) -> Self
where
Self: Sized;

/// Returns the first known backtrace, either from its State or from one
/// of the errors from `foreign_links`.
#[doc(hidden)]
#[allow(unknown_lints, bare_trait_objects)]
fn extract_backtrace(e: &(error::Error + Send + 'static)) -> Option<InternalBacktrace>
where Self: Sized;
where
Self: Sized;
}

/// A struct which formats an error for output.
#[derive(Debug)]
pub struct DisplayChain<'a, T: 'a + ?Sized>(&'a T);

impl<'a, T> fmt::Display for DisplayChain<'a, T>
where T: ChainedError
where
T: ChainedError,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
// Keep `try!` for 1.10 support
Expand Down Expand Up @@ -686,8 +694,7 @@ impl State {
/// Creates a new State type
#[allow(unknown_lints, bare_trait_objects)]
pub fn new<CE: ChainedError>(e: Box<error::Error + Send>) -> State {
let backtrace = CE::extract_backtrace(&*e)
.unwrap_or_else(InternalBacktrace::new);
let backtrace = CE::extract_backtrace(&*e).unwrap_or_else(InternalBacktrace::new);
State {
next_error: Some(e),
backtrace: backtrace,
Expand Down Expand Up @@ -814,5 +821,5 @@ macro_rules! ensure {

#[doc(hidden)]
pub mod mock {
error_chain!{}
error_chain! {}
}
10 changes: 7 additions & 3 deletions src/quick_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@
macro_rules! quick_main {
($main:expr) => {
fn main() {
use ::std::io::Write;
use std::io::Write;

::std::process::exit(match $main() {
Ok(ret) => $crate::ExitCode::code(ret),
Err(ref e) => {
write!(&mut ::std::io::stderr(), "{}", $crate::ChainedError::display_chain(e))
.expect("Error writing to stderr");
write!(
&mut ::std::io::stderr(),
"{}",
$crate::ChainedError::display_chain(e)
)
.expect("Error writing to stderr");

1
}
Expand Down
Loading