diff --git a/Cargo.toml b/Cargo.toml index 58426fc..3e5edc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,8 +26,10 @@ futures = ["dep:futures-util"] tokio = ["dep:tokio"] [dev-dependencies] +anyhow = "1.0.100" indoc = "2.0.7" pretty_assertions = "1.4.1" +tokio = { version = "1.48.0", features = ["macros", "net", "rt"] } [build-dependencies] lalrpop = "0.22.2" diff --git a/examples/mpd-client/main.rs b/examples/mpd-client/main.rs index 98ecdb0..09e8f98 100644 --- a/examples/mpd-client/main.rs +++ b/examples/mpd-client/main.rs @@ -1,3 +1,14 @@ -fn main() { - todo!() +use empidee::MpdClient; + +#[tokio::main(flavor = "current_thread")] +async fn main() -> anyhow::Result<()> { + let socket = tokio::net::TcpSocket::new_v4()?; + let mut stream = socket.connect("127.0.0.1:6600".parse()?).await?; + + let mut client = MpdClient::new(&mut stream); + println!("{}", client.read_initial_mpd_version().await?); + + client.play(None).await?; + + Ok(()) } diff --git a/src/client.rs b/src/client.rs index a032772..a0c5379 100644 --- a/src/client.rs +++ b/src/client.rs @@ -42,7 +42,7 @@ where MpdClient { connection } } - async fn read_initial_mpd_version(&mut self) -> Result { + pub async fn read_initial_mpd_version(&mut self) -> Result { let mut reader = BufReader::new(&mut self.connection); let mut version_line = String::new(); @@ -98,9 +98,7 @@ where .map_err(MpdClientError::ConnectionError)?; let response_bytes = self.read_response().await?; - let response = PlayResponse::parse_raw(&response_bytes)?; - Ok(response) } } diff --git a/src/commands.rs b/src/commands.rs index efb3fe0..e4eab65 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -428,7 +428,6 @@ pub(crate) use multi_item_command_response; pub(crate) use single_item_command_request; pub(crate) use single_item_command_response; pub(crate) use single_optional_item_command_request; -use thiserror::Error; #[derive(Debug, Clone, PartialEq)] pub enum RequestParserError { diff --git a/src/lib.rs b/src/lib.rs index 7387134..37d0f45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ mod server; pub mod filter; pub mod types; -pub use client::MpdClient; +pub use client::{MpdClient, MpdClientError}; pub use request::Request; pub use response::Response; pub use server::MpdServer;