summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 59f3b99..fd8cc59 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -25,7 +25,6 @@ use std::error::Error;
25use std::fmt::{self, Display}; 25use std::fmt::{self, Display};
26use std::fs; 26use std::fs;
27use std::io::{Read, Write}; 27use std::io::{Read, Write};
28use std::iter::FromIterator;
29 28
30/// Brave's adblocking library in Python! 29/// Brave's adblocking library in Python!
31#[pymodule] 30#[pymodule]
@@ -170,7 +169,7 @@ pub struct HostnameSpecificResources {
170 /// A set of any CSS selector on the page that should be hidden, i.e. 169 /// A set of any CSS selector on the page that should be hidden, i.e.
171 /// styled as `{ display: none !important; }`. 170 /// styled as `{ display: none !important; }`.
172 #[pyo3(get)] 171 #[pyo3(get)]
173 pub hide_selectors: Vec<String>, 172 pub hide_selectors: HashSet<String>,
174 /// A map of CSS selectors on the page to respective non-hide style rules, 173 /// A map of CSS selectors on the page to respective non-hide style rules,
175 /// i.e. any required styles other than `display: none`. 174 /// i.e. any required styles other than `display: none`.
176 #[pyo3(get)] 175 #[pyo3(get)]
@@ -180,7 +179,7 @@ pub struct HostnameSpecificResources {
180 // In practice, these should be passed to `class_id_stylesheet` and not 179 // In practice, these should be passed to `class_id_stylesheet` and not
181 // used otherwise. 180 // used otherwise.
182 #[pyo3(get)] 181 #[pyo3(get)]
183 pub exceptions: Vec<String>, 182 pub exceptions: HashSet<String>,
184 /// Javascript code for any scriptlets that should be injected into the 183 /// Javascript code for any scriptlets that should be injected into the
185 /// page. 184 /// page.
186 #[pyo3(get)] 185 #[pyo3(get)]
@@ -189,12 +188,10 @@ pub struct HostnameSpecificResources {
189 188
190impl Into<HostnameSpecificResources> for RustHostnameSpecificResources { 189impl Into<HostnameSpecificResources> for RustHostnameSpecificResources {
191 fn into(self) -> HostnameSpecificResources { 190 fn into(self) -> HostnameSpecificResources {
192 let hide_selectors = Vec::from_iter(self.hide_selectors.into_iter());
193 let exceptions = Vec::from_iter(self.exceptions.into_iter());
194 HostnameSpecificResources { 191 HostnameSpecificResources {
195 hide_selectors, 192 hide_selectors: self.hide_selectors,
196 style_selectors: self.style_selectors, 193 style_selectors: self.style_selectors,
197 exceptions, 194 exceptions: self.exceptions,
198 injected_script: self.injected_script, 195 injected_script: self.injected_script,
199 } 196 }
200 } 197 }
@@ -433,20 +430,15 @@ impl Engine {
433 /// are not excepted. 430 /// are not excepted.
434 /// 431 ///
435 /// Exceptions should be passed directly from HostnameSpecificResources. 432 /// Exceptions should be passed directly from HostnameSpecificResources.
436 ///
437 /// ## Note
438 /// The `exceptions` field will be changed to a set, once a new version of
439 /// PyO3 is released.
440 #[text_signature = "($self, classes, ids, exceptions)"] 433 #[text_signature = "($self, classes, ids, exceptions)"]
441 pub fn hidden_class_id_selectors( 434 pub fn hidden_class_id_selectors(
442 &self, 435 &self,
443 classes: Vec<String>, 436 classes: Vec<String>,
444 ids: Vec<String>, 437 ids: Vec<String>,
445 exceptions: Vec<String>, 438 exceptions: HashSet<String>,
446 ) -> PyResult<Vec<String>> { 439 ) -> PyResult<Vec<String>> {
447 let exception_hashset: HashSet<String> = HashSet::from_iter(exceptions);
448 Ok(self 440 Ok(self
449 .engine 441 .engine
450 .hidden_class_id_selectors(&classes, &ids, &exception_hashset)) 442 .hidden_class_id_selectors(&classes, &ids, &exceptions))
451 } 443 }
452} 444}