Skip to content

Commit

Permalink
clippy and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rokob committed Mar 14, 2019
1 parent a330579 commit 89cd3a6
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 29 deletions.
6 changes: 6 additions & 0 deletions builder_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ pub fn builder(input: TokenStream) -> TokenStream {
})
.map(|(n, t, o)| {
if let Some(ty) = o {
let maybe_name = Ident::new(&format!("maybe_{}", n.clone().unwrap()), name.span());
quote_spanned! { name.span() =>
pub fn #n<T: Into<#ty>>(mut self, val: T) -> Self {
self.node.#n = Some(val.into());
self
}

pub fn #maybe_name(mut self, val: Option<#ty>) -> Self {
self.node.#n = val;
self
}
}
} else {
quote_spanned! { name.span() =>
Expand Down
6 changes: 6 additions & 0 deletions core/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use crate::types::Level;
pub struct Configuration {
pub endpoint: String,
pub access_token: Option<String>,
pub environment: Option<String>,
pub host: Option<String>,
pub code_version: Option<String>,
pub log_level: Level,
pub timeout: u64,
}
Expand All @@ -14,6 +17,9 @@ impl Default for Configuration {
Configuration {
endpoint: "https://api.rollbar.com/api/1/item/".to_owned(),
access_token: None,
environment: None,
host: None,
code_version: None,
log_level: Level::Info,
timeout: 10,
}
Expand Down
13 changes: 9 additions & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#[macro_use] extern crate log;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate builder_derive;
#[macro_use] extern crate error_chain;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate builder_derive;
#[macro_use]
extern crate error_chain;

mod configuration;
mod errors;
Expand All @@ -14,6 +18,7 @@ pub use log::Level;
pub use crate::configuration::Configuration;
pub use crate::transport::{HttpTransport, Transport};

#[derive(Default)]
pub struct Uuid(uuid::Uuid);

impl Uuid {
Expand Down
5 changes: 3 additions & 2 deletions core/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[macro_use] extern crate log;
#[macro_use]
extern crate log;

use rollbar_rust::constants;
use rollbar_rust::types::*;
Expand All @@ -17,7 +18,7 @@ fn main() {

fn make_configuration() -> Configuration {
let mut conf = Configuration::default();
conf.access_token = Some("a4ced289a17c42928fb4b7fdba5f2ce0".to_owned());
conf.access_token = Some("POST_SERVER_ITEM_TOKEN".to_owned());
conf
}

Expand Down
13 changes: 6 additions & 7 deletions core/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl HttpTransport {
.timeout(Duration::from_secs(configuration.timeout))
.build()
.unwrap();
#[allow(clippy::mutex_atomic)]
let queue_depth = Arc::new(Mutex::new(0));
let endpoint = configuration.endpoint.clone();
let _handle = Some(spawn_sender(
Expand Down Expand Up @@ -75,13 +76,11 @@ impl Transport for HttpTransport {
sender.send(None).ok();
}
return true;
} else {
if let Ok(sender) = self.sender.lock() {
match sender.try_send(None) {
Err(TrySendError::Full(_)) => {}
Ok(_) | Err(_) => {
return self.signal.wait_timeout(guard, timeout).is_ok();
}
} else if let Ok(sender) = self.sender.lock() {
match sender.try_send(None) {
Err(TrySendError::Full(_)) => {}
Ok(_) | Err(_) => {
return self.signal.wait_timeout(guard, timeout).is_ok();
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ impl<'a> From<&'a str> for Level {

impl ToString for Level {
fn to_string(&self) -> String {
match self {
&Level::Critical => "critical",
&Level::Error => "error",
&Level::Warning => "warning",
&Level::Info => "info",
&Level::Debug => "debug",
match *self {
Level::Critical => "critical",
Level::Error => "error",
Level::Warning => "warning",
Level::Info => "info",
Level::Debug => "debug",
}
.to_string()
}
Expand Down Expand Up @@ -321,6 +321,7 @@ impl<'de> ::serde::Deserialize<'de> for Level {
}
}

#[derive(Default)]
pub struct BodyBuilder {
telemetry: Option<Vec<Telemetry>>,
}
Expand Down
18 changes: 10 additions & 8 deletions pyagent/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use std::mem;

const DEFAULT: &'static str = "DEFAULT";
const DEFAULT: &str = "DEFAULT";

#[derive(Debug)]
pub struct Configuration {
Expand Down Expand Up @@ -140,7 +140,7 @@ impl App {

pub fn validate(&self) -> Result<()> {
if let Some(ts) = &self.targets {
if ts.len() == 0 {
if ts.is_empty() {
bail!(ErrorKind::MissingTargets(self.name.clone()));
}
} else {
Expand Down Expand Up @@ -239,14 +239,14 @@ impl Configuration {
}
}

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

pub fn validate(&self) -> Result<()> {
for (_name, app) in &self.apps {
for app in self.apps.values() {
app.validate()?;
}
Ok(())
Expand Down Expand Up @@ -374,19 +374,19 @@ impl ConfigurationBuilder {
Ok(())
}

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

fn convert_to_bool(&self, value: &String) -> bool {
fn convert_to_bool(&self, value: &str) -> bool {
match &value[..] {
"false" | "False" | "FALSE" | "no" | "No" | "NO" => false,
_ => true,
}
}

fn convert_to_pair_list(&self, value: &String) -> Result<Vec<Vec<String>>> {
fn convert_to_pair_list(&self, value: &str) -> Result<Vec<Vec<String>>> {
let mut iter = value.split_whitespace();
let mut result = Vec::new();
loop {
Expand All @@ -395,7 +395,9 @@ impl ConfigurationBuilder {
result.push(vec![regex.to_string(), name.to_string()]);
}
(None, None) => break,
_ => return Err(ErrorKind::BadInput("log_format.patterns", value.clone()).into()),
_ => {
return Err(ErrorKind::BadInput("log_format.patterns", value.to_owned()).into());
}
}
}
Ok(result)
Expand Down
4 changes: 2 additions & 2 deletions pyagent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate error_chain;

use std::fs;

const VERSION: &'static str = "0.4.3";
const VERSION: &str = "0.4.3";

mod cli;
mod configuration;
Expand Down Expand Up @@ -39,7 +39,7 @@ fn run() -> Result<()> {
let config = builder.build();
simple_logger::init_with_level(config.log_level()).chain_err(|| "simple logger failed?")?;
config.validate()?;
write_config_to_file("converted.toml", config.to_toml()?)
write_config_to_file("converted.toml", config.into_toml()?)
}

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

0 comments on commit 89cd3a6

Please sign in to comment.