bluez-async 0.8.2

An async wrapper around the D-Bus interface of BlueZ (the Linux Bluetooth daemon), supporting GATT client (central) functionality.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use dbus::Path;
use serde::de::Error as _;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::ops::Deref;

/// Serialize a [`Path`] as a string.
pub fn serialize<S: Serializer>(path: &Path, serializer: S) -> Result<S::Ok, S::Error> {
    path.deref().serialize(serializer)
}

/// Deserialize a [`Path`] from a string.
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Path<'static>, D::Error> {
    let string = String::deserialize(deserializer)?;
    Ok(Path::new(string).map_err(|e| D::Error::custom(format!("Invalid D-Bus path: {:?}", e)))?)
}