mirror of
https://github.com/talwat/lowfi
synced 2025-12-09 16:34:12 +00:00
style: use and instead of redundant extra function
This commit is contained in:
parent
4f3fa02cb4
commit
af8d45905f
20
src/main.rs
20
src/main.rs
@ -7,6 +7,7 @@ mod tests;
|
|||||||
pub use error::{Error, Result};
|
pub use error::{Error, Result};
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
|
use futures_util::TryFutureExt;
|
||||||
pub use message::Message;
|
pub use message::Message;
|
||||||
|
|
||||||
use crate::player::Player;
|
use crate::player::Player;
|
||||||
@ -96,19 +97,6 @@ pub fn data_dir() -> crate::Result<PathBuf> {
|
|||||||
Ok(dir)
|
Ok(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simply creates and runs the player, so that the [`Result`] of both operations
|
|
||||||
/// can be easily handled by the [`main`] function.
|
|
||||||
async fn player(
|
|
||||||
args: Args,
|
|
||||||
environment: ui::Environment,
|
|
||||||
mixer: &rodio::mixer::Mixer,
|
|
||||||
) -> crate::Result<()> {
|
|
||||||
let mut player = Player::init(args, environment, mixer).await?;
|
|
||||||
player.run().await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Program entry point.
|
/// Program entry point.
|
||||||
///
|
///
|
||||||
/// Parses CLI arguments, initializes the audio stream and player, then
|
/// Parses CLI arguments, initializes the audio stream and player, then
|
||||||
@ -131,8 +119,10 @@ async fn main() -> eyre::Result<()> {
|
|||||||
|
|
||||||
let stream = audio::stream()?;
|
let stream = audio::stream()?;
|
||||||
let environment = ui::Environment::ready(args.alternate)?;
|
let environment = ui::Environment::ready(args.alternate)?;
|
||||||
let result = player(args, environment, stream.mixer()).await;
|
let result = Player::init(args, environment, stream.mixer())
|
||||||
environment.cleanup(result.is_ok())?;
|
.and_then(Player::run)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
environment.cleanup(result.is_ok())?;
|
||||||
Ok(result?)
|
Ok(result?)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -176,7 +176,7 @@ impl Player {
|
|||||||
///
|
///
|
||||||
/// This will return when a `Message::Quit` is received. It handles commands
|
/// This will return when a `Message::Quit` is received. It handles commands
|
||||||
/// coming from the frontend and updates playback/UI state accordingly.
|
/// coming from the frontend and updates playback/UI state accordingly.
|
||||||
pub async fn run(&mut self) -> crate::Result<()> {
|
pub async fn run(mut self) -> crate::Result<()> {
|
||||||
while let Some(message) = self.rx.recv().await {
|
while let Some(message) = self.rx.recv().await {
|
||||||
match message {
|
match message {
|
||||||
Message::Next | Message::Init | Message::Loaded => {
|
Message::Next | Message::Init | Message::Loaded => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user