Skip to content

Commit

Permalink
chore: fix some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
abusch committed Feb 24, 2024
1 parent 3f7a305 commit 367c448
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async fn main() {
// be visible on the screen
let prev = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
term::reset_term().unwrap();
term::reset().unwrap();
prev(info);
}));

Expand Down Expand Up @@ -101,7 +101,7 @@ async fn run_app(provided_names: Vec<String>, provided_ips: Vec<Ipv4Addr>) -> Re
sonos.start((provided_ips, provided_names));

// Initialize the terminal user interface.
let (mut terminal, _cleanup) = term::init_crossterm()?;
let (mut terminal, _cleanup) = term::init()?;

let mut events = EventStream::new();

Expand Down
10 changes: 5 additions & 5 deletions src/sonos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ impl SonosService {
async fn get_speakers(provided_devices: (Vec<Ipv4Addr>, Vec<String>)) -> Result<Vec<Speaker>> {
let mut speakers: Vec<Speaker> = vec![];
debug!("Connecting to provided speakers...");
for e in provided_devices.0.iter() {
for e in &provided_devices.0 {
if let Some(spk) = sonor::Speaker::from_ip(*e).await.unwrap_or(None) {
speakers.push(spk);
} else {
debug!("Not connecting to {} due to errors", e);
debug!("Not connecting to {e} due to errors");
}
}
for e in provided_devices.1.iter() {
for e in &provided_devices.1 {
if let Some(device) = sonor::find(e, Duration::from_secs(2)).await? {
speakers.push(device);
} else {
debug!("Not connecting to {} due to errors", e);
debug!("Not connecting to {e} due to errors");
}
}
if provided_devices.0.is_empty() && provided_devices.1.is_empty() {
Expand Down Expand Up @@ -243,7 +243,7 @@ impl SpeakerGroup {
}

fn name(&self) -> String {
let names: Vec<_> = self.speakers.iter().map(|s| s.name()).collect();
let names: Vec<_> = self.speakers.iter().map(SpeakerInfo::name).collect();
names.join(" + ")
}
}
6 changes: 3 additions & 3 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crossterm::{
};
use tui::{backend::CrosstermBackend, Terminal};

pub fn init_crossterm() -> Result<(Terminal<CrosstermBackend<io::Stdout>>, OnShutdown)> {
pub fn init() -> Result<(Terminal<CrosstermBackend<io::Stdout>>, OnShutdown)> {
terminal::enable_raw_mode().context("Failed to enable crossterm raw mode")?;

let mut stdout = std::io::stdout();
Expand All @@ -18,13 +18,13 @@ pub fn init_crossterm() -> Result<(Terminal<CrosstermBackend<io::Stdout>>, OnShu

let cleanup = OnShutdown::new(|| {
// Be a good terminal citizen...
reset_term()
reset()
});

Ok((term, cleanup))
}

pub fn reset_term() -> Result<()> {
pub fn reset() -> Result<()> {
let mut stdout = std::io::stdout();
crossterm::execute!(stdout, LeaveAlternateScreen, DisableMouseCapture)
.context("Failed to disable crossterm alternate screen and mouse capture")?;
Expand Down
4 changes: 2 additions & 2 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn render_playbar(state: &SpeakerState, frame: &mut Frame, area: Rect) {
let (np, label, ratio) = if let Some(track) = &state.now_playing {
let percent = if track.duration() != 0 {
f64::clamp(
(track.elapsed() as f64) / (track.duration() as f64),
f64::from(track.elapsed()) / f64::from(track.duration()),
0.0,
1.0,
)
Expand Down Expand Up @@ -186,5 +186,5 @@ fn format_duration(secs: u32) -> String {
let minutes = secs / 60;
let seconds = secs % 60;

format!("{}:{:02}", minutes, seconds)
format!("{minutes}:{seconds:02}")
}

0 comments on commit 367c448

Please sign in to comment.