Skip to content

Commit

Permalink
Fix many pedantic clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Grund <jgrund@whamcloud.io>
  • Loading branch information
jgrund committed Apr 15, 2019
1 parent c28f9c8 commit c49768b
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions iml-agent-comms/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Host {

impl Host {
pub fn new(fqdn: Fqdn, client_start_time: String) -> Self {
Host {
Self {
fqdn,
client_start_time,
queue: Arc::new(Mutex::new(VecDeque::new())),
Expand All @@ -40,7 +40,7 @@ pub fn shared_hosts() -> SharedHosts {
Arc::new(Mutex::new(HashMap::new()))
}

/// Does this host entry have a different start_time than the remote host?
/// Does this host entry have a different `start_time` than the remote host?
pub fn is_stale(hosts: &mut Hosts, fqdn: &Fqdn, client_start_time: &str) -> bool {
match hosts.get(fqdn) {
Some(h) if h.client_start_time != client_start_time => true,
Expand Down
38 changes: 19 additions & 19 deletions iml-agent-comms/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ struct MessageFqdn {
pub fqdn: Fqdn,
}

/// Creates a warp `Filter` that will hand out
/// a cloned client for each request.
pub fn create_client_filter() -> (
impl Future<Item = (), Error = ()>,
impl Filter<Extract = (TcpClient,), Error = warp::Rejection> + Clone,
) {
let (tx, fut) = iml_rabbit::get_cloned_conns(iml_rabbit::connect_to_rabbit());

let filter = warp::any().and_then(move || {
let (tx2, rx2) = oneshot::channel();

tx.unbounded_send(tx2).unwrap();

rx2.map_err(warp::reject::custom)
});

(fut, filter)
}

fn main() {
env_logger::init();

Expand Down Expand Up @@ -170,25 +189,6 @@ fn main() {

let hosts = warp::any().map(move || Arc::clone(&hosts_state2));

/// Creates a warp `Filter` that will hand out
/// a cloned client for each request.
pub fn create_client_filter() -> (
impl Future<Item = (), Error = ()>,
impl Filter<Extract = (TcpClient,), Error = warp::Rejection> + Clone,
) {
let (tx, fut) = iml_rabbit::get_cloned_conns(iml_rabbit::connect_to_rabbit());

let filter = warp::any().and_then(move || {
let (tx2, rx2) = oneshot::channel();

tx.unbounded_send(tx2).unwrap();

rx2.map_err(warp::reject::custom)
});

(fut, filter)
}

let (fut, client_filter) = create_client_filter();

tokio::spawn(fut);
Expand Down
6 changes: 3 additions & 3 deletions iml-agent-comms/src/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl std::fmt::Display for AgentData {
}
}

/// Converts agent Message out of it's enum and into a discrete AgentData
/// Converts agent Message out of it's enum and into a discrete `AgentData`
/// struct. This function will panic if the Message is not Data.
impl From<Message> for AgentData {
fn from(msg: Message) -> Self {
Expand All @@ -42,7 +42,7 @@ impl From<Message> for AgentData {
session_seq,
body,
..
} => AgentData {
} => Self {
fqdn,
plugin,
session_id,
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn consume_agent_tx_queue(
Some(BasicConsumeOptions {
no_ack: true,
exclusive: true,
..Default::default()
..BasicConsumeOptions::default()
}),
)
})
Expand Down
2 changes: 1 addition & 1 deletion iml-agent-comms/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl std::fmt::Display for Session {

impl Session {
pub fn new(plugin: PluginName, fqdn: Fqdn) -> Self {
Session {
Self {
fqdn,
id: Id(Uuid::new_v4().to_hyphenated().to_string()),
plugin,
Expand Down
2 changes: 1 addition & 1 deletion iml-agent/src/action_plugins/action_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where

pub type Actions = HashMap<ActionName, Callback>;

/// The registry of available actions to the AgentDaemon.
/// The registry of available actions to the `AgentDaemon`.
/// Add new Actions to the fn body as they are created.
pub fn create_registry() -> HashMap<ActionName, Callback> {
let mut map = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion iml-agent/src/daemon_plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

//! # DaemonPlugins
//! # `DaemonPlugins`
//!
//! Provides an extensible plugin interface for long-running plugins.
//!
Expand Down
2 changes: 1 addition & 1 deletion iml-agent/src/http_comms/agent_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct AgentClient {

impl AgentClient {
pub fn new(start_time: String, message_endpoint: url::Url, client: Client) -> Self {
AgentClient {
Self {
start_time,
message_endpoint,
client,
Expand Down
6 changes: 3 additions & 3 deletions iml-agent/src/http_comms/crypto_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ mod tests {

#[test]
fn test_post() -> Result<()> {
#[derive(serde::Serialize)]
struct Foo {}

let m = mock("POST", "/agent/message")
.with_status(201)
.with_header("content-type", "application/json")
Expand All @@ -140,9 +143,6 @@ mod tests {

let url = create_url()?;

#[derive(serde::Serialize)]
struct Foo {}

let r = Runtime::new()
.unwrap()
.block_on_all(post(&Client::new(), url, &Foo {}))?;
Expand Down
6 changes: 3 additions & 3 deletions iml-agent/src/http_comms/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ impl State {
pub struct Sessions(Arc<Mutex<HashMap<PluginName, State>>>);

impl Sessions {
pub fn new(plugins: &[PluginName]) -> Sessions {
pub fn new(plugins: &[PluginName]) -> Self {
let hm = plugins
.iter()
.cloned()
.map(|x| (x, State::Empty(Instant::now())))
.collect();

Sessions(Arc::new(Mutex::new(hm)))
Self(Arc::new(Mutex::new(hm)))
}
pub fn reset_active(&mut self, name: &PluginName) -> Result<()> {
if let Some(x) = self.lock().get_mut(name) {
Expand Down Expand Up @@ -160,7 +160,7 @@ impl Session {
pub fn new(name: PluginName, id: Id, plugin: DaemonBox) -> Self {
log::info!("Created new session {:?}/{:?}", name, id);

Session {
Self {
info: SessionInfo {
name,
id,
Expand Down
12 changes: 6 additions & 6 deletions iml-manager-env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fn get_var(name: &str) -> String {
env::var(name).unwrap_or_else(|_| panic!("{} environment variable is required.", name))
}

/// Convert a given host and port to a SocketAddr or panic
fn to_socket_addr(host: String, port: String) -> SocketAddr {
/// Convert a given host and port to a `SocketAddr` or panic
fn to_socket_addr(host: &str, port: &str) -> SocketAddr {
let raw_addr = format!("{}:{}", host, port);

let mut addrs_iter = raw_addr.to_socket_addrs().unwrap_or_else(|_| {
Expand Down Expand Up @@ -53,13 +53,13 @@ pub fn get_port() -> String {
get_var("AMQP_BROKER_PORT")
}

/// Get the http_agent2 port from the env or panic
/// Get the `http_agent2` port from the env or panic
pub fn get_http_agent2_port() -> String {
get_var("HTTP_AGENT2_PORT")
}

pub fn get_http_agent2_addr() -> SocketAddr {
to_socket_addr(get_server_host(), get_http_agent2_port())
to_socket_addr(&get_server_host(), &get_http_agent2_port())
}

/// Get the server host from the env or panic
Expand All @@ -69,7 +69,7 @@ pub fn get_server_host() -> String {

/// Get the AMQP server address or panic
pub fn get_addr() -> SocketAddr {
to_socket_addr(get_host(), get_port())
to_socket_addr(&get_host(), &get_port())
}

/// Get the server port from the env or panic
Expand All @@ -78,5 +78,5 @@ pub fn get_warp_drive_port() -> String {
}

pub fn get_warp_drive_addr() -> SocketAddr {
to_socket_addr(get_server_host(), get_warp_drive_port())
to_socket_addr(&get_server_host(), &get_warp_drive_port())
}
8 changes: 4 additions & 4 deletions iml-rabbit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn create_channel(client: TcpClient) -> impl TcpChannelFuture {
///
/// # Arguments
///
/// * `channel` - The TcpChannel to use
/// * `channel` - The `TcpChannel` to use
pub fn close_channel(channel: TcpChannel) -> impl Future<Item = (), Error = failure::Error> {
let id = channel.id;

Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn declare_transient_exchange(
exchange_type,
Some(ExchangeDeclareOptions {
durable: false,
..Default::default()
..ExchangeDeclareOptions::default()
}),
)
}
Expand Down Expand Up @@ -177,7 +177,7 @@ pub fn declare_transient_queue(
name,
Some(QueueDeclareOptions {
durable: false,
..Default::default()
..QueueDeclareOptions::default()
}),
)
}
Expand Down Expand Up @@ -383,7 +383,7 @@ mod tests {
queue_name,
BasicGetOptions {
no_ack: true,
..Default::default()
..BasicGetOptions::default()
},
)
.map_err(failure::Error::from)
Expand Down
2 changes: 1 addition & 1 deletion iml-services/src/service_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn consume_service_queue(
Some(BasicConsumeOptions {
no_ack: true,
exclusive: true,
..Default::default()
..BasicConsumeOptions::default()
}),
)
})
Expand Down
2 changes: 1 addition & 1 deletion iml-services/src/services/action_runner/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct ActionInFlight {

impl ActionInFlight {
pub fn new(action: Action, tx: Sender) -> Self {
ActionInFlight { action, tx }
Self { action, tx }
}
pub fn complete(
self,
Expand Down
2 changes: 1 addition & 1 deletion iml-services/src/services/action_runner/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use iml_wire_types::Fqdn;
use tokio::timer;

/// Encapsulates any errors that may happen while working with the ActionRunner service
/// Encapsulates any errors that may happen while working with the `ActionRunner` service
#[derive(Debug)]
pub enum ActionRunnerError {
AwaitSession(Fqdn),
Expand Down
4 changes: 2 additions & 2 deletions iml-warp-drive/src/locks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn create_locks_consumer(
Some(BasicConsumeOptions {
no_ack: true,
exclusive: true,
..Default::default()
..BasicConsumeOptions::default()
}),
)
})
Expand Down Expand Up @@ -96,7 +96,7 @@ impl LockChange {
}
}

/// Need to wrap LockChange with this, because it's how
/// Need to wrap `LockChange` with this, because it's how
/// the RPC layer in IML returns RPC calls.
#[derive(serde_derive::Deserialize, serde_derive::Serialize, Debug, Eq, PartialEq)]
pub struct Response {
Expand Down
4 changes: 2 additions & 2 deletions iml-warp-drive/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub struct Request {
}

impl Request {
pub fn new<S>(method: S, response_routing_key: S) -> Request
pub fn new<S>(method: S, response_routing_key: S) -> Self
where
S: Into<String> + std::cmp::Eq + std::hash::Hash,
{
Request {
Self {
request_id: Uuid::new_v4().to_hyphenated().to_string(),
method: method.into(),
args: vec![],
Expand Down
10 changes: 5 additions & 5 deletions iml-wire-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ pub struct PluginName(pub String);

impl PluginName {
pub fn new<S: Into<String>>(name: S) -> Self {
PluginName(name.into())
Self(name.into())
}
}

impl From<PluginName> for String {
fn from(PluginName(s): PluginName) -> String {
fn from(PluginName(s): PluginName) -> Self {
s
}
}
Expand All @@ -32,7 +32,7 @@ impl fmt::Display for PluginName {
pub struct Fqdn(pub String);

impl From<Fqdn> for String {
fn from(Fqdn(s): Fqdn) -> String {
fn from(Fqdn(s): Fqdn) -> Self {
s
}
}
Expand All @@ -58,7 +58,7 @@ impl fmt::Display for Id {
pub struct Seq(pub u64);

impl std::ops::AddAssign for Seq {
fn add_assign(&mut self, Seq(y): Seq) {
fn add_assign(&mut self, Self(y): Self) {
self.0 += y;
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Envelope {
client_start_time: impl Into<String>,
server_boot_time: impl Into<String>,
) -> Self {
Envelope {
Self {
messages,
server_boot_time: server_boot_time.into(),
client_start_time: client_start_time.into(),
Expand Down
2 changes: 1 addition & 1 deletion liblustreapi-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub type lstat_t = libc::stat;
#[cfg(target_os = "linux")]
pub type lstat_t = libc::stat64;

pub const IOC_MDC_GETFILEINFO: u32 = 0xc0086916;
pub const IOC_MDC_GETFILEINFO: u32 = 0xc008_6916;

#[cfg(test)]
mod tests {}
Loading

0 comments on commit c49768b

Please sign in to comment.