summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2019-10-17 21:39:59 +0200
committerAram Drevekenin <aram@poor.dev>2019-10-17 21:39:59 +0200
commitb6eda322be7a0f9f7d30f662578d5e236d167f82 (patch)
treee2d9e647512497fd7282b78e9d9708fb79a6741c
parent50b4e6471eef5400158071b156b4a3faeba29063 (diff)
style(lint): rustfmt + clippy
-rw-r--r--src/display/components/layout.rs22
-rw-r--r--src/main.rs4
-rw-r--r--src/os/linux.rs14
-rw-r--r--src/tests/fakes/fake_input.rs39
4 files changed, 36 insertions, 43 deletions
diff --git a/src/display/components/layout.rs b/src/display/components/layout.rs
index 1f20f68..e5ca069 100644
--- a/src/display/components/layout.rs
+++ b/src/display/components/layout.rs
@@ -25,16 +25,18 @@ pub struct Layout<'a> {
impl<'a> Layout<'a> {
fn progressive_split(&self, rect: Rect, splits: Vec<Direction>) -> Vec<Rect> {
- splits.into_iter().fold(vec![rect], |mut layout, direction| {
- let last_rect = layout.pop().unwrap();
- let mut halves = ::tui::layout::Layout::default()
- .direction(direction)
- .margin(0)
- .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
- .split(last_rect);
- layout.append(&mut halves);
- layout
- })
+ splits
+ .into_iter()
+ .fold(vec![rect], |mut layout, direction| {
+ let last_rect = layout.pop().unwrap();
+ let mut halves = ::tui::layout::Layout::default()
+ .direction(direction)
+ .margin(0)
+ .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
+ .split(last_rect);
+ layout.append(&mut halves);
+ layout
+ })
}
fn build_layout(&self, rect: Rect) -> Vec<Rect> {
if rect.height < FIRST_HEIGHT_BREAKPOINT && rect.width < FIRST_WIDTH_BREAKPOINT {
diff --git a/src/main.rs b/src/main.rs
index 3921a66..efa1fad 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -46,7 +46,7 @@ fn try_main() -> Result<(), failure::Error> {
"Sorry, no implementations for platforms other than linux yet :( - PRs welcome!"
);
- use os::{get_input};
+ use os::get_input;
let opt = Opt::from_args();
let os_input = get_input(opt)?;
let stdout = match io::stdout().into_raw_mode() {
@@ -66,7 +66,7 @@ pub struct OsInput {
pub get_open_sockets: fn() -> HashMap<Connection, String>,
pub keyboard_events: Box<Iterator<Item = Event> + Send>,
pub lookup_addr: Box<Fn(&IpAddr) -> Option<String> + Send>,
- pub on_winch: Box<Fn(Box<Fn()>)+ Send>,
+ pub on_winch: Box<Fn(Box<Fn()>) + Send>,
pub cleanup: Box<Fn() + Send>,
}
diff --git a/src/os/linux.rs b/src/os/linux.rs
index cc2d883..f231d12 100644
--- a/src/os/linux.rs
+++ b/src/os/linux.rs
@@ -9,8 +9,8 @@ use ::std::collections::HashMap;
use ::std::net::IpAddr;
use ::std::time;
-use signal_hook::iterator::Signals;
use ::procfs::FDTarget;
+use signal_hook::iterator::Signals;
use crate::network::{Connection, Protocol};
use crate::{Opt, OsInput};
@@ -27,16 +27,15 @@ impl Iterator for KeyboardEvents {
}
}
-fn get_datalink_channel(interface: &NetworkInterface) -> Result<Box<DataLinkReceiver>, failure::Error> {
+fn get_datalink_channel(
+ interface: &NetworkInterface,
+) -> Result<Box<DataLinkReceiver>, failure::Error> {
let mut config = Config::default();
config.read_timeout = Some(time::Duration::new(0, 1));
match datalink::channel(interface, config) {
Ok(Ethernet(_tx, rx)) => Ok(rx),
Ok(_) => failure::bail!("Unknown interface type"),
- Err(e) => failure::bail!(
- "Failed to listen to network interface: {}",
- e
- ),
+ Err(e) => failure::bail!("Failed to listen to network interface: {}", e),
}
}
@@ -90,7 +89,7 @@ fn lookup_addr(ip: &IpAddr) -> Option<String> {
::dns_lookup::lookup_addr(ip).ok()
}
-fn sigwinch () -> (Box<Fn(Box<Fn()>) + Send>, Box<Fn() + Send>) {
+fn sigwinch() -> (Box<Fn(Box<Fn()>) + Send>, Box<Fn() + Send>) {
let signals = Signals::new(&[signal_hook::SIGWINCH]).unwrap();
let on_winch = {
let signals = signals.clone();
@@ -110,7 +109,6 @@ fn sigwinch () -> (Box<Fn(Box<Fn()>) + Send>, Box<Fn() + Send>) {
}
pub fn get_input(opt: Opt) -> Result<OsInput, failure::Error> {
-
let keyboard_events = Box::new(KeyboardEvents);
let network_interface = match get_interface(&opt.interface) {
Some(interface) => interface,
diff --git a/src/tests/fakes/fake_input.rs b/src/tests/fakes/fake_input.rs
index 1cd5fa4..831d4fb 100644
--- a/src/tests/fakes/fake_input.rs
+++ b/src/tests/fakes/fake_input.rs
@@ -22,15 +22,13 @@ impl Iterator for KeyboardEvents {
type Item = Event;
fn next(&mut self) -> Option<Event> {
match self.events.pop() {
- Some(ev) => {
- match ev {
- Some(ev) => Some(ev),
- None => {
- thread::sleep(time::Duration::from_secs(1));
- self.next()
- }
+ Some(ev) => match ev {
+ Some(ev) => Some(ev),
+ None => {
+ thread::sleep(time::Duration::from_secs(1));
+ self.next()
}
- }
+ },
None => None,
}
}
@@ -61,23 +59,18 @@ impl DataLinkReceiver for NetworkFrames {
// this is so the tests pass consistently
thread::sleep(time::Duration::from_millis(500));
}
- match self.current_index < self.packets.len() {
- true => {
- let action = self.next_packet();
- match action {
- Some(packet) => {
- Ok(&packet[..])
- }
- None => {
- thread::sleep(time::Duration::from_secs(1));
- Ok(&[][..])
- }
+ if self.current_index < self.packets.len() {
+ let action = self.next_packet();
+ match action {
+ Some(packet) => Ok(&packet[..]),
+ None => {
+ thread::sleep(time::Duration::from_secs(1));
+ Ok(&[][..])
}
}
- false => {
- thread::sleep(time::Duration::from_secs(1));
- Ok(&[][..])
- }
+ } else {
+ thread::sleep(time::Duration::from_secs(1));
+ Ok(&[][..])
}
}
}