style(lint): rustfmt + clippy

This commit is contained in:
Aram Drevekenin
2019-10-17 21:39:59 +02:00
parent 50b4e6471e
commit b6eda322be
4 changed files with 36 additions and 43 deletions

View File

@@ -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 {

View File

@@ -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>,
}

View File

@@ -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,

View File

@@ -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(&[][..])
}
}
}