Skip to content

Commit 0f35362

Browse files
committed
Reformat source.
1 parent 3fc1ba5 commit 0f35362

File tree

3 files changed

+46
-33
lines changed

3 files changed

+46
-33
lines changed

benches/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#![feature(test)]
2-
32
extern crate test;
4-
53
#[macro_use]
64
extern crate throw;
75

6+
use std::result::Result as StdResult;
7+
88
use test::Bencher;
99
use throw::Result;
10-
use std::result::Result as StdResult;
1110

1211
#[inline(never)]
1312
fn gives_throw_ok() -> Result<&'static str, &'static str> {

src/lib.rs

+35-26
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@
195195
//! To have `serde::{Serialize, Deserialize}` implemented on Throw types, depend on throw with
196196
//! `features = ["serde-1-std"]` or `features = ["serde-1"]` for no-std environments.
197197
198+
#[cfg(not(feature = "std"))]
199+
#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), macro_use)]
200+
extern crate alloc;
201+
202+
#[cfg(any(feature = "serde-1", feature = "serde-1-std"))]
203+
extern crate serde;
204+
#[cfg(any(feature = "serde-1", feature = "serde-1-std"))]
205+
#[macro_use]
206+
extern crate serde_derive;
207+
198208
#[cfg(feature = "std")]
199209
mod core {
200210
pub use std::fmt;
@@ -204,27 +214,23 @@ mod core {
204214
use core::fmt;
205215

206216
#[cfg(not(feature = "std"))]
207-
#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), macro_use)]
208-
extern crate alloc;
209-
217+
use alloc::string::String;
210218
#[cfg(not(feature = "std"))]
211219
use alloc::vec::Vec;
212-
#[cfg(not(feature = "std"))]
213-
use alloc::string::String;
214-
215-
#[cfg(any(feature = "serde-1", feature = "serde-1-std"))]
216-
extern crate serde;
217-
#[cfg(any(feature = "serde-1", feature = "serde-1-std"))]
218-
#[macro_use]
219-
extern crate serde_derive;
220220

221221
#[cfg(any(feature = "serde-1", feature = "serde-1-std"))]
222222
use serde::ser::{Serialize, SerializeStruct, Serializer};
223223

224224
/// Types allowed to be value in the context vector
225225
#[derive(Debug, Clone)]
226-
#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), derive(Serialize))]
227-
#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), serde(untagged))]
226+
#[cfg_attr(
227+
any(feature = "serde-1", feature = "serde-1-std"),
228+
derive(Serialize)
229+
)]
230+
#[cfg_attr(
231+
any(feature = "serde-1", feature = "serde-1-std"),
232+
serde(untagged)
233+
)]
228234
pub enum ThrowContextValues {
229235
///Boolean
230236
Bool(bool),
@@ -351,7 +357,10 @@ pub type Result<T, E> = core::result::Result<T, Error<E>>;
351357

352358
/// Represents a location at which an error was thrown via throw!()
353359
#[derive(Debug)]
354-
#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), derive(Serialize))]
360+
#[cfg_attr(
361+
any(feature = "serde-1", feature = "serde-1-std"),
362+
derive(Serialize)
363+
)]
355364
pub struct ErrorPoint {
356365
line: u32,
357366
column: u32,
@@ -402,7 +411,10 @@ impl ErrorPoint {
402411

403412
/// represent a key-value pair
404413
#[derive(Debug, Clone)]
405-
#[cfg_attr(any(feature = "serde-1", feature = "serde-1-std"), derive(Serialize))]
414+
#[cfg_attr(
415+
any(feature = "serde-1", feature = "serde-1-std"),
416+
derive(Serialize)
417+
)]
406418
pub struct KvPair {
407419
key: &'static str,
408420
value: ThrowContextValues,
@@ -599,13 +611,13 @@ macro_rules! up {
599611
return Err(me);
600612
},
601613
}
602-
)
614+
);
603615
}
604616

605617
#[doc(hidden)]
606618
#[macro_export]
607619
macro_rules! __with_new_errorpoint {
608-
($e:expr) => ({
620+
($e:expr) => {{
609621
let mut e = $e;
610622
e.__push_point($crate::ErrorPoint::__construct(
611623
line!(),
@@ -614,7 +626,7 @@ macro_rules! __with_new_errorpoint {
614626
file!(),
615627
));
616628
e
617-
})
629+
}};
618630
}
619631

620632
#[macro_export]
@@ -625,27 +637,24 @@ macro_rules! throw {
625637
Err(e) => throw_new!(e),
626638
}
627639
);
628-
629-
($e:expr, $($key:expr => $value:expr),+ $(,)*) => ({
640+
($e:expr, $($key:expr => $value:expr),+ $(,)*) => ({
630641
match $e {
631642
Ok(v) => v,
632643
Err(e) => throw_new!(e, $($key => $value,)*),
633644
}
634-
})
645+
});
635646
}
636647

637648
#[macro_export]
638649
macro_rules! throw_new {
639-
($e:expr) => ({
650+
($e:expr) => ({
640651
return Err(__with_new_errorpoint!($crate::Error::new($e.into())));
641652
});
642-
643-
($e:expr, $($key:expr => $value:expr),+ $(,)*) => ({
653+
($e:expr, $($key:expr => $value:expr),+ $(,)*) => ({
644654
let mut me = $crate::Error::new($e.into());
645655
$(
646656
me.add_context($key, $value);
647657
)*
648658
return Err(__with_new_errorpoint!(me));
649-
650-
})
659+
});
651660
}

tests/exceptions_work.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ extern crate throw;
77
use throw::Result;
88

99
macro_rules! assert_matches {
10-
($expected:expr, $actual:expr) => ({
10+
($expected:expr, $actual:expr) => {{
1111
let expected = ($expected).replace(" ", "\t");
1212
let re = regex::Regex::new(&expected).expect("expected hardcoded regex to compile");
1313

1414
let actual = format!("{}", $actual);
1515

16-
assert!(re.is_match(&actual),
17-
format!("expected error to match regex `\n{}\n`, but found `\n{}\n`", expected, actual));
18-
})
16+
assert!(
17+
re.is_match(&actual),
18+
format!(
19+
"expected error to match regex `\n{}\n`, but found `\n{}\n`",
20+
expected, actual
21+
)
22+
);
23+
}};
1924
}
2025

2126
fn throw_static_message() -> Result<(), &'static str> {

0 commit comments

Comments
 (0)