mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
Format component bluetooth_traits
This commit is contained in:
parent
949e50d662
commit
0e3131a54c
3 changed files with 47 additions and 37 deletions
|
@ -10,24 +10,17 @@ use std::string::String;
|
|||
|
||||
const EXCLUDE_READS: &'static str = "exclude-reads";
|
||||
const EXCLUDE_WRITES: &'static str = "exclude-writes";
|
||||
const VALID_UUID_REGEX: &'static str = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
||||
const VALID_UUID_REGEX: &'static str =
|
||||
"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
||||
|
||||
thread_local!(pub static BLUETOOTH_BLOCKLIST: RefCell<BluetoothBlocklist> =
|
||||
RefCell::new(BluetoothBlocklist(parse_blocklist())));
|
||||
|
||||
pub fn uuid_is_blocklisted(uuid: &str, exclude_type: Blocklist) -> bool {
|
||||
BLUETOOTH_BLOCKLIST.with(|blist| {
|
||||
match exclude_type {
|
||||
Blocklist::All => {
|
||||
blist.borrow().is_blocklisted(uuid)
|
||||
},
|
||||
Blocklist::Reads => {
|
||||
blist.borrow().is_blocklisted_for_reads(uuid)
|
||||
}
|
||||
Blocklist::Writes => {
|
||||
blist.borrow().is_blocklisted_for_writes(uuid)
|
||||
}
|
||||
}
|
||||
BLUETOOTH_BLOCKLIST.with(|blist| match exclude_type {
|
||||
Blocklist::All => blist.borrow().is_blocklisted(uuid),
|
||||
Blocklist::Reads => blist.borrow().is_blocklisted_for_reads(uuid),
|
||||
Blocklist::Writes => blist.borrow().is_blocklisted_for_writes(uuid),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -52,8 +45,9 @@ impl BluetoothBlocklist {
|
|||
// https://webbluetoothcg.github.io/web-bluetooth/#blocklisted-for-reads
|
||||
pub fn is_blocklisted_for_reads(&self, uuid: &str) -> bool {
|
||||
match self.0 {
|
||||
Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&Blocklist::All) ||
|
||||
et.eq(&Blocklist::Reads)),
|
||||
Some(ref map) => map.get(uuid).map_or(false, |et| {
|
||||
et.eq(&Blocklist::All) || et.eq(&Blocklist::Reads)
|
||||
}),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
@ -61,8 +55,9 @@ impl BluetoothBlocklist {
|
|||
// https://webbluetoothcg.github.io/web-bluetooth/#blocklisted-for-writes
|
||||
pub fn is_blocklisted_for_writes(&self, uuid: &str) -> bool {
|
||||
match self.0 {
|
||||
Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&Blocklist::All) ||
|
||||
et.eq(&Blocklist::Writes)),
|
||||
Some(ref map) => map.get(uuid).map_or(false, |et| {
|
||||
et.eq(&Blocklist::All) || et.eq(&Blocklist::Writes)
|
||||
}),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +93,7 @@ fn parse_blocklist() -> Option<HashMap<String, Blocklist>> {
|
|||
exclude_type = Blocklist::Reads;
|
||||
},
|
||||
Some(EXCLUDE_WRITES) => {
|
||||
exclude_type = Blocklist::Writes;
|
||||
exclude_type = Blocklist::Writes;
|
||||
},
|
||||
// Step 4.4
|
||||
_ => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue