examples/mpd-client: add some code
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ where
|
||||
MpdClient { connection }
|
||||
}
|
||||
|
||||
async fn read_initial_mpd_version(&mut self) -> Result<String, MpdClientError> {
|
||||
pub async fn read_initial_mpd_version(&mut self) -> Result<String, MpdClientError> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user