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

Commit 8462495

Browse files
Atul9AndyGauge
authored andcommitted
Format code using 'cargo fmt' (#280)
1 parent 5d1f3c7 commit 8462495

File tree

9 files changed

+95
-66
lines changed

9 files changed

+95
-66
lines changed

examples/all.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
extern crate error_chain;
33

44
pub mod inner {
5-
error_chain!{}
5+
error_chain! {}
66
}
77

88
#[cfg(feature = "a_feature")]
99
pub mod feature {
10-
error_chain!{}
10+
error_chain! {}
1111
}
1212

1313
error_chain! {

examples/chain_err.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ extern crate error_chain;
77
use std::fs::File;
88

99
mod errors {
10-
use std::io;
1110
use super::LaunchStage;
11+
use std::io;
1212

1313
error_chain! {
1414
foreign_links {
@@ -54,11 +54,9 @@ fn load_config(rel_path: &str) -> Result<()> {
5454
/// Launch the service.
5555
fn launch(rel_path: &str) -> Result<()> {
5656
load_config(rel_path).map_err(|e| match e {
57-
e @ Error(ErrorKind::ConfigLoad(_), _) => {
58-
e.chain_err(|| LaunchStage::ConfigLoad)
59-
}
60-
e => e.chain_err(|| "Unknown failure"),
61-
})
57+
e @ Error(ErrorKind::ConfigLoad(_), _) => e.chain_err(|| LaunchStage::ConfigLoad),
58+
e => e.chain_err(|| "Unknown failure"),
59+
})
6260
}
6361

6462
fn main() {

examples/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern crate error_chain;
77

88
/// Inner module.
99
pub mod inner {
10-
error_chain!{}
10+
error_chain! {}
1111
}
1212

1313
error_chain! {

examples/quickstart.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern crate error_chain;
1414
// `error_chain!` creates.
1515
mod errors {
1616
// Create the Error, ErrorKind, ResultExt, and Result types
17-
error_chain!{}
17+
error_chain! {}
1818
}
1919

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

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

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

7574
// This operation will fail
76-
File::open("tretrete")
77-
.chain_err(|| "unable to open tretrete file")?;
75+
File::open("tretrete").chain_err(|| "unable to open tretrete file")?;
7876

7977
Ok(())
8078
}

src/backtrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mod imp {
4343
};
4444
ENABLED.store(enabled as usize + 1, Ordering::SeqCst);
4545
if !enabled {
46-
return InternalBacktrace { backtrace: None }
46+
return InternalBacktrace { backtrace: None };
4747
}
4848
}
4949
1 => return InternalBacktrace { backtrace: None },

src/example_generated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
2222
/// Another code generated by the macro.
2323
pub mod inner {
24-
error_chain!{}
24+
error_chain! {}
2525
}
2626

2727
error_chain! {

src/lib.rs

+21-14
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,8 @@
540540
//! [`BacktraceFrame`]: https://docs.rs/backtrace/0.3.2/backtrace/struct.BacktraceFrame.html
541541
542542
use std::error;
543-
use std::iter::Iterator;
544543
use std::fmt;
544+
use std::iter::Iterator;
545545

546546
#[macro_use]
547547
mod impl_error_chain_kind;
@@ -550,9 +550,9 @@ mod error_chain;
550550
#[macro_use]
551551
mod quick_main;
552552
pub use quick_main::ExitCode;
553+
mod backtrace;
553554
#[cfg(feature = "example_generated")]
554555
pub mod example_generated;
555-
mod backtrace;
556556
pub use backtrace::Backtrace;
557557
#[doc(hidden)]
558558
pub use backtrace::InternalBacktrace;
@@ -597,13 +597,16 @@ pub trait ChainedError: error::Error + Send + 'static {
597597
type ErrorKind;
598598

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

602604
/// Constructs a chained error from another error and a kind, and generates a backtrace.
603605
fn with_chain<E, K>(error: E, kind: K) -> Self
604-
where Self: Sized,
605-
E: ::std::error::Error + Send + 'static,
606-
K: Into<Self::ErrorKind>;
606+
where
607+
Self: Sized,
608+
E: ::std::error::Error + Send + 'static,
609+
K: Into<Self::ErrorKind>;
607610

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

625628
/// Extends the error chain with a new entry.
626629
fn chain_err<F, EK>(self, error: F) -> Self
627-
where F: FnOnce() -> EK,
628-
EK: Into<Self::ErrorKind>;
630+
where
631+
F: FnOnce() -> EK,
632+
EK: Into<Self::ErrorKind>;
629633

630634
/// Creates an error from its parts.
631635
#[doc(hidden)]
632-
fn new(kind: Self::ErrorKind, state: State) -> Self where Self: Sized;
636+
fn new(kind: Self::ErrorKind, state: State) -> Self
637+
where
638+
Self: Sized;
633639

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

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

646653
impl<'a, T> fmt::Display for DisplayChain<'a, T>
647-
where T: ChainedError
654+
where
655+
T: ChainedError,
648656
{
649657
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
650658
writeln!(fmt, "Error: {}", self.0)?;
@@ -685,8 +693,7 @@ impl State {
685693
/// Creates a new State type
686694
#[allow(unknown_lints, bare_trait_objects)]
687695
pub fn new<CE: ChainedError>(e: Box<error::Error + Send>) -> State {
688-
let backtrace = CE::extract_backtrace(&*e)
689-
.unwrap_or_else(InternalBacktrace::new);
696+
let backtrace = CE::extract_backtrace(&*e).unwrap_or_else(InternalBacktrace::new);
690697
State {
691698
next_error: Some(e),
692699
backtrace: backtrace,
@@ -813,5 +820,5 @@ macro_rules! ensure {
813820

814821
#[doc(hidden)]
815822
pub mod mock {
816-
error_chain!{}
823+
error_chain! {}
817824
}

src/quick_main.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@
4242
macro_rules! quick_main {
4343
($main:expr) => {
4444
fn main() {
45-
use ::std::io::Write;
45+
use std::io::Write;
4646

4747
::std::process::exit(match $main() {
4848
Ok(ret) => $crate::ExitCode::code(ret),
4949
Err(ref e) => {
50-
write!(&mut ::std::io::stderr(), "{}", $crate::ChainedError::display_chain(e))
51-
.expect("Error writing to stderr");
50+
write!(
51+
&mut ::std::io::stderr(),
52+
"{}",
53+
$crate::ChainedError::display_chain(e)
54+
)
55+
.expect("Error writing to stderr");
5256

5357
1
5458
}

0 commit comments

Comments
 (0)