Skip to content

Commit 437023c

Browse files
committed
ref: cargo fmt
1 parent 1c28a66 commit 437023c

File tree

6 files changed

+270
-207
lines changed

6 files changed

+270
-207
lines changed

src/dsn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::str::FromStr;
44
use url::Url;
55

66
use project_id::{ProjectId, ProjectIdParseError};
7-
use auth::{Auth, auth_from_dsn_and_client};
7+
use auth::{auth_from_dsn_and_client, Auth};
88

99
/// Represents a dsn url parsing error.
1010
#[derive(Debug, Fail)]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ extern crate chrono;
4040
extern crate failure;
4141
#[macro_use]
4242
extern crate failure_derive;
43+
extern crate linked_hash_map;
4344
extern crate serde;
4445
#[macro_use]
4546
extern crate serde_derive;
4647
extern crate serde_json;
4748
extern crate url;
4849
extern crate url_serde;
4950
extern crate uuid;
50-
extern crate linked_hash_map;
5151

5252
#[macro_use]
5353
mod macros;

src/protocol/v7.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ use utils::ts_seconds_float;
1919

2020
/// An arbitrary (JSON) value (`serde_json::value::Value`)
2121
pub mod value {
22-
pub use serde_json::value::{Map, Value, Index, Number, from_value, to_value};
22+
pub use serde_json::value::{from_value, to_value, Index, Map, Number, Value};
2323
}
2424

2525
/// The internally use arbitrary data map type (`linked_hash_map::LinkedHashMap`)
2626
///
2727
/// It is currently backed by the `linked-hash-map` crate's hash map so that
2828
/// insertion order is preserved.
2929
pub mod map {
30-
pub use linked_hash_map::{Entries, IntoIter, Iter, IterMut, Keys,
31-
LinkedHashMap, OccupiedEntry,
32-
VacantEntry, Values};
30+
pub use linked_hash_map::{Entries, IntoIter, Iter, IterMut, Keys, LinkedHashMap,
31+
OccupiedEntry, VacantEntry, Values};
3332
}
3433

3534
/// An arbitrary (JSON) value (`serde_json::value::Value`)
@@ -308,7 +307,6 @@ pub struct Thread {
308307
pub current: bool,
309308
}
310309

311-
312310
/// Represents a single exception
313311
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
314312
pub struct Exception {
@@ -1061,16 +1059,18 @@ impl<'de> Deserialize<'de> for Addr {
10611059
Uint(u64),
10621060
}
10631061

1064-
Ok(Addr(match Repr::deserialize(deserializer).map_err(D::Error::custom)? {
1065-
Repr::Str(s) => {
1066-
if s.len() > 2 && (&s[..2] == "0x" || &s[..2] == "0X") {
1067-
u64::from_str_radix(&s[2..], 16).map_err(D::Error::custom)?
1068-
} else {
1069-
u64::from_str_radix(&s, 10).map_err(D::Error::custom)?
1062+
Ok(Addr(
1063+
match Repr::deserialize(deserializer).map_err(D::Error::custom)? {
1064+
Repr::Str(s) => {
1065+
if s.len() > 2 && (&s[..2] == "0x" || &s[..2] == "0X") {
1066+
u64::from_str_radix(&s[2..], 16).map_err(D::Error::custom)?
1067+
} else {
1068+
u64::from_str_radix(&s, 10).map_err(D::Error::custom)?
1069+
}
10701070
}
1071-
}
1072-
Repr::Uint(val) => val
1073-
}))
1071+
Repr::Uint(val) => val,
1072+
},
1073+
))
10741074
}
10751075
}
10761076

src/utils.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use chrono::{DateTime, Utc, TimeZone};
1+
use chrono::{DateTime, TimeZone, Utc};
22

33
/// Converts a datetime object into a float timestamp.
44
pub fn datetime_to_timestamp(dt: &DateTime<Utc>) -> f64 {
55
if dt.timestamp_subsec_nanos() == 0 {
66
dt.timestamp() as f64
77
} else {
8-
(dt.timestamp() as f64) +
9-
((dt.timestamp_subsec_micros() as f64) / 1_000_000f64)
8+
(dt.timestamp() as f64) + ((dt.timestamp_subsec_micros() as f64) / 1_000_000f64)
109
}
1110
}
1211

@@ -16,30 +15,30 @@ pub fn timestamp_to_datetime(ts: f64) -> DateTime<Utc> {
1615
Utc.timestamp_opt(secs, micros * 1000).unwrap()
1716
}
1817

19-
2018
pub mod ts_seconds_float {
2119
use std::fmt;
22-
use serde::{ser, de};
23-
use chrono::{DateTime, Utc, TimeZone};
20+
use serde::{de, ser};
21+
use chrono::{DateTime, TimeZone, Utc};
2422

2523
use super::timestamp_to_datetime;
2624

2725
pub fn deserialize<'de, D>(d: D) -> Result<DateTime<Utc>, D::Error>
28-
where D: de::Deserializer<'de>
26+
where
27+
D: de::Deserializer<'de>,
2928
{
3029
Ok(d.deserialize_any(SecondsTimestampVisitor)
31-
.map(|dt| dt.with_timezone(&Utc))?)
30+
.map(|dt| dt.with_timezone(&Utc))?)
3231
}
3332

3433
pub fn serialize<S>(dt: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
35-
where S: ser::Serializer
34+
where
35+
S: ser::Serializer,
3636
{
3737
if dt.timestamp_subsec_nanos() == 0 {
3838
serializer.serialize_i64(dt.timestamp())
3939
} else {
4040
serializer.serialize_f64(
41-
(dt.timestamp() as f64) +
42-
((dt.timestamp_subsec_micros() as f64) / 1_000_000f64)
41+
(dt.timestamp() as f64) + ((dt.timestamp_subsec_micros() as f64) / 1_000_000f64),
4342
)
4443
}
4544
}
@@ -49,25 +48,27 @@ pub mod ts_seconds_float {
4948
impl<'de> de::Visitor<'de> for SecondsTimestampVisitor {
5049
type Value = DateTime<Utc>;
5150

52-
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
53-
{
51+
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
5452
write!(formatter, "a unix timestamp")
5553
}
5654

5755
fn visit_f64<E>(self, value: f64) -> Result<DateTime<Utc>, E>
58-
where E: de::Error
56+
where
57+
E: de::Error,
5958
{
6059
Ok(timestamp_to_datetime(value))
6160
}
6261

6362
fn visit_i64<E>(self, value: i64) -> Result<DateTime<Utc>, E>
64-
where E: de::Error
63+
where
64+
E: de::Error,
6565
{
6666
Ok(Utc.timestamp_opt(value, 0).unwrap())
6767
}
6868

6969
fn visit_u64<E>(self, value: u64) -> Result<DateTime<Utc>, E>
70-
where E: de::Error
70+
where
71+
E: de::Error,
7172
{
7273
Ok(Utc.timestamp_opt(value as i64, 0).unwrap())
7374
}

tests/test_auth.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
extern crate chrono;
22
extern crate sentry_types;
33
use chrono::{TimeZone, Utc};
4-
use sentry_types::{Auth, Dsn, protocol};
5-
4+
use sentry_types::{protocol, Auth, Dsn};
65

76
#[test]
87
fn test_auth_parsing() {
@@ -13,7 +12,10 @@ fn test_auth_parsing() {
1312
sentry_secret=secret"
1413
.parse()
1514
.unwrap();
16-
assert_eq!(auth.timestamp(), Some(Utc.ymd(2012, 2, 1).and_hms_milli(0, 14, 46, 500)));
15+
assert_eq!(
16+
auth.timestamp(),
17+
Some(Utc.ymd(2012, 2, 1).and_hms_milli(0, 14, 46, 500))
18+
);
1719
assert_eq!(auth.client_agent(), Some("raven-python/42"));
1820
assert_eq!(auth.version(), 6);
1921
assert_eq!(auth.public_key(), "public");

0 commit comments

Comments
 (0)