Add method for fetching string props, fetch version

This commit is contained in:
Aode (lion) 2021-10-02 17:05:19 -05:00
parent a3c115a035
commit 86dbd2eaed

View file

@ -25,11 +25,15 @@ pub async fn identity(port: &mut SerialStream) -> Result<Vec<u8>, Error> {
}
pub async fn author(port: &mut SerialStream) -> Result<String, Error> {
Ok(String::from_utf8(get_prop(port, b"author").await?)?)
get_string_prop(port, b"author").await
}
pub async fn repo(port: &mut SerialStream) -> Result<String, Error> {
Ok(String::from_utf8(get_prop(port, b"repo").await?)?)
get_string_prop(port, b"repo").await
}
pub async fn version(port: &mut SerialStream) -> Result<String, Error> {
get_string_prop(port, b"version").await
}
pub async fn reset(port: &mut SerialStream) -> Result<(), Error> {
@ -46,6 +50,13 @@ where
Ok(())
}
async fn get_string_prop<Port>(port: &mut Port, prop: &[u8]) -> Result<String, Error>
where
Port: AsyncRead + AsyncWrite + Unpin,
{
Ok(String::from_utf8(get_prop(port, prop).await?)?)
}
async fn get_prop<Port>(port: &mut Port, prop: &[u8]) -> Result<Vec<u8>, Error>
where
Port: AsyncRead + AsyncWrite + Unpin,