Skip to content

Commit 89cd3a6

Browse files
committed
clippy and fmt
1 parent a330579 commit 89cd3a6

File tree

8 files changed

+49
-29
lines changed

8 files changed

+49
-29
lines changed

builder_derive/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ pub fn builder(input: TokenStream) -> TokenStream {
5050
})
5151
.map(|(n, t, o)| {
5252
if let Some(ty) = o {
53+
let maybe_name = Ident::new(&format!("maybe_{}", n.clone().unwrap()), name.span());
5354
quote_spanned! { name.span() =>
5455
pub fn #n<T: Into<#ty>>(mut self, val: T) -> Self {
5556
self.node.#n = Some(val.into());
5657
self
5758
}
59+
60+
pub fn #maybe_name(mut self, val: Option<#ty>) -> Self {
61+
self.node.#n = val;
62+
self
63+
}
5864
}
5965
} else {
6066
quote_spanned! { name.span() =>

core/src/configuration.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use crate::types::Level;
55
pub struct Configuration {
66
pub endpoint: String,
77
pub access_token: Option<String>,
8+
pub environment: Option<String>,
9+
pub host: Option<String>,
10+
pub code_version: Option<String>,
811
pub log_level: Level,
912
pub timeout: u64,
1013
}
@@ -14,6 +17,9 @@ impl Default for Configuration {
1417
Configuration {
1518
endpoint: "https://api.rollbar.com/api/1/item/".to_owned(),
1619
access_token: None,
20+
environment: None,
21+
host: None,
22+
code_version: None,
1723
log_level: Level::Info,
1824
timeout: 10,
1925
}

core/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
#[macro_use] extern crate log;
2-
#[macro_use] extern crate serde_derive;
3-
#[macro_use] extern crate builder_derive;
4-
#[macro_use] extern crate error_chain;
1+
#[macro_use]
2+
extern crate log;
3+
#[macro_use]
4+
extern crate serde_derive;
5+
#[macro_use]
6+
extern crate builder_derive;
7+
#[macro_use]
8+
extern crate error_chain;
59

610
mod configuration;
711
mod errors;
@@ -14,6 +18,7 @@ pub use log::Level;
1418
pub use crate::configuration::Configuration;
1519
pub use crate::transport::{HttpTransport, Transport};
1620

21+
#[derive(Default)]
1722
pub struct Uuid(uuid::Uuid);
1823

1924
impl Uuid {

core/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#[macro_use] extern crate log;
1+
#[macro_use]
2+
extern crate log;
23

34
use rollbar_rust::constants;
45
use rollbar_rust::types::*;
@@ -17,7 +18,7 @@ fn main() {
1718

1819
fn make_configuration() -> Configuration {
1920
let mut conf = Configuration::default();
20-
conf.access_token = Some("a4ced289a17c42928fb4b7fdba5f2ce0".to_owned());
21+
conf.access_token = Some("POST_SERVER_ITEM_TOKEN".to_owned());
2122
conf
2223
}
2324

core/src/transport.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl HttpTransport {
3737
.timeout(Duration::from_secs(configuration.timeout))
3838
.build()
3939
.unwrap();
40+
#[allow(clippy::mutex_atomic)]
4041
let queue_depth = Arc::new(Mutex::new(0));
4142
let endpoint = configuration.endpoint.clone();
4243
let _handle = Some(spawn_sender(
@@ -75,13 +76,11 @@ impl Transport for HttpTransport {
7576
sender.send(None).ok();
7677
}
7778
return true;
78-
} else {
79-
if let Ok(sender) = self.sender.lock() {
80-
match sender.try_send(None) {
81-
Err(TrySendError::Full(_)) => {}
82-
Ok(_) | Err(_) => {
83-
return self.signal.wait_timeout(guard, timeout).is_ok();
84-
}
79+
} else if let Ok(sender) = self.sender.lock() {
80+
match sender.try_send(None) {
81+
Err(TrySendError::Full(_)) => {}
82+
Ok(_) | Err(_) => {
83+
return self.signal.wait_timeout(guard, timeout).is_ok();
8584
}
8685
}
8786
}

core/src/types.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ impl<'a> From<&'a str> for Level {
278278

279279
impl ToString for Level {
280280
fn to_string(&self) -> String {
281-
match self {
282-
&Level::Critical => "critical",
283-
&Level::Error => "error",
284-
&Level::Warning => "warning",
285-
&Level::Info => "info",
286-
&Level::Debug => "debug",
281+
match *self {
282+
Level::Critical => "critical",
283+
Level::Error => "error",
284+
Level::Warning => "warning",
285+
Level::Info => "info",
286+
Level::Debug => "debug",
287287
}
288288
.to_string()
289289
}
@@ -321,6 +321,7 @@ impl<'de> ::serde::Deserialize<'de> for Level {
321321
}
322322
}
323323

324+
#[derive(Default)]
324325
pub struct BodyBuilder {
325326
telemetry: Option<Vec<Telemetry>>,
326327
}

pyagent/src/configuration.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde_derive::{Deserialize, Serialize};
55
use std::collections::HashMap;
66
use std::mem;
77

8-
const DEFAULT: &'static str = "DEFAULT";
8+
const DEFAULT: &str = "DEFAULT";
99

1010
#[derive(Debug)]
1111
pub struct Configuration {
@@ -140,7 +140,7 @@ impl App {
140140

141141
pub fn validate(&self) -> Result<()> {
142142
if let Some(ts) = &self.targets {
143-
if ts.len() == 0 {
143+
if ts.is_empty() {
144144
bail!(ErrorKind::MissingTargets(self.name.clone()));
145145
}
146146
} else {
@@ -239,14 +239,14 @@ impl Configuration {
239239
}
240240
}
241241

242-
pub fn to_toml(self) -> Result<String> {
242+
pub fn into_toml(self) -> Result<String> {
243243
debug!("Starting conversion to TOML");
244244
let conf = TomlConfiguration::from(self);
245245
toml::to_string(&conf).chain_err(|| "bad toml data")
246246
}
247247

248248
pub fn validate(&self) -> Result<()> {
249-
for (_name, app) in &self.apps {
249+
for app in self.apps.values() {
250250
app.validate()?;
251251
}
252252
Ok(())
@@ -374,19 +374,19 @@ impl ConfigurationBuilder {
374374
Ok(())
375375
}
376376

377-
fn convert_to_list(&self, value: &String) -> Vec<String> {
377+
fn convert_to_list(&self, value: &str) -> Vec<String> {
378378
let parts: Vec<_> = value.split_whitespace().collect();
379379
parts.iter().map(|s| s.to_string()).collect()
380380
}
381381

382-
fn convert_to_bool(&self, value: &String) -> bool {
382+
fn convert_to_bool(&self, value: &str) -> bool {
383383
match &value[..] {
384384
"false" | "False" | "FALSE" | "no" | "No" | "NO" => false,
385385
_ => true,
386386
}
387387
}
388388

389-
fn convert_to_pair_list(&self, value: &String) -> Result<Vec<Vec<String>>> {
389+
fn convert_to_pair_list(&self, value: &str) -> Result<Vec<Vec<String>>> {
390390
let mut iter = value.split_whitespace();
391391
let mut result = Vec::new();
392392
loop {
@@ -395,7 +395,9 @@ impl ConfigurationBuilder {
395395
result.push(vec![regex.to_string(), name.to_string()]);
396396
}
397397
(None, None) => break,
398-
_ => return Err(ErrorKind::BadInput("log_format.patterns", value.clone()).into()),
398+
_ => {
399+
return Err(ErrorKind::BadInput("log_format.patterns", value.to_owned()).into());
400+
}
399401
}
400402
}
401403
Ok(result)

pyagent/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate error_chain;
55

66
use std::fs;
77

8-
const VERSION: &'static str = "0.4.3";
8+
const VERSION: &str = "0.4.3";
99

1010
mod cli;
1111
mod configuration;
@@ -39,7 +39,7 @@ fn run() -> Result<()> {
3939
let config = builder.build();
4040
simple_logger::init_with_level(config.log_level()).chain_err(|| "simple logger failed?")?;
4141
config.validate()?;
42-
write_config_to_file("converted.toml", config.to_toml()?)
42+
write_config_to_file("converted.toml", config.into_toml()?)
4343
}
4444

4545
fn write_config_to_file(filename: &str, config: String) -> Result<()> {

0 commit comments

Comments
 (0)