tapo/responses/
decodable_result_ext.rs1use base64::{Engine as _, engine::general_purpose};
2
3use crate::error::Error;
4
5pub(crate) trait DecodableResultExt
7where
8 Self: Sized,
9{
10 fn decode(self) -> Result<Self, Error>;
12}
13
14impl DecodableResultExt for serde_json::Value {
15 fn decode(self) -> Result<Self, Error> {
16 Ok(self)
17 }
18}
19
20pub(crate) fn decode_value(value: &str) -> anyhow::Result<String> {
21 let decoded_bytes = general_purpose::STANDARD.decode(value)?;
22 Ok(std::str::from_utf8(&decoded_bytes)?.to_string())
23}