diff --git a/src/main.rs b/src/main.rs index a2c3d0e..2a50596 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ mod tests; pub use error::{Error, Result}; pub mod message; pub mod ui; +use futures_util::TryFutureExt; pub use message::Message; use crate::player::Player; @@ -96,19 +97,6 @@ pub fn data_dir() -> crate::Result { 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. /// /// Parses CLI arguments, initializes the audio stream and player, then @@ -131,8 +119,10 @@ async fn main() -> eyre::Result<()> { let stream = audio::stream()?; let environment = ui::Environment::ready(args.alternate)?; - let result = player(args, environment, stream.mixer()).await; - environment.cleanup(result.is_ok())?; + let result = Player::init(args, environment, stream.mixer()) + .and_then(Player::run) + .await; + environment.cleanup(result.is_ok())?; Ok(result?) } diff --git a/src/player.rs b/src/player.rs index f9ddf0c..0768c22 100644 --- a/src/player.rs +++ b/src/player.rs @@ -176,7 +176,7 @@ impl Player { /// /// This will return when a `Message::Quit` is received. It handles commands /// 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 { match message { Message::Next | Message::Init | Message::Loaded => {