deviceplug / btleplug

Rust Cross-Platform Host-Side Bluetooth LE Access Library
Other
814 stars 150 forks source link

add PeripheralId new method for android #396

Open Yongle-Fu opened 2 months ago

Yongle-Fu commented 2 months ago
pub fn to_peripheral_id(id: *const c_char) -> PeripheralId {
    let id_str = unsafe { CStr::from_ptr(id) };
    let id_str = id_str.to_str().expect("Invalid UTF-8 sequence");
    info!("to_peripheral_id, id_str: {:?}", id_str);

    #[cfg(any(target_os = "macos", target_os = "ios"))]
    return PeripheralId::from(Uuid::parse_str(id_str).unwrap());

    #[cfg(target_os = "android")]
    return PeripheralId(BDAddr::from_str_delim(&id_str).unwrap());

    #[cfg(target_os = "windows")]
    PeripheralId::from(BDAddr::from_str_delim(&id_str).unwrap())
}

why not provide public method

droidplug/peripheral.rs:42:25 | 42 | pub struct PeripheralId(pub(super) BDAddr); | ^^^^^^^^^^^^^^^^^ private field