From dd4240bdd40108dc6f7845075ab26586327e74d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81rni=20Dagur?= Date: Fri, 15 May 2020 00:45:12 -0400 Subject: Turn a few fields from Vec to HashSet, now that we're running PyO3 0.10 --- src/lib.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'src') 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; use std::fmt::{self, Display}; use std::fs; use std::io::{Read, Write}; -use std::iter::FromIterator; /// Brave's adblocking library in Python! #[pymodule] @@ -170,7 +169,7 @@ pub struct HostnameSpecificResources { /// A set of any CSS selector on the page that should be hidden, i.e. /// styled as `{ display: none !important; }`. #[pyo3(get)] - pub hide_selectors: Vec, + pub hide_selectors: HashSet, /// A map of CSS selectors on the page to respective non-hide style rules, /// i.e. any required styles other than `display: none`. #[pyo3(get)] @@ -180,7 +179,7 @@ pub struct HostnameSpecificResources { // In practice, these should be passed to `class_id_stylesheet` and not // used otherwise. #[pyo3(get)] - pub exceptions: Vec, + pub exceptions: HashSet, /// Javascript code for any scriptlets that should be injected into the /// page. #[pyo3(get)] @@ -189,12 +188,10 @@ pub struct HostnameSpecificResources { impl Into for RustHostnameSpecificResources { fn into(self) -> HostnameSpecificResources { - let hide_selectors = Vec::from_iter(self.hide_selectors.into_iter()); - let exceptions = Vec::from_iter(self.exceptions.into_iter()); HostnameSpecificResources { - hide_selectors, + hide_selectors: self.hide_selectors, style_selectors: self.style_selectors, - exceptions, + exceptions: self.exceptions, injected_script: self.injected_script, } } @@ -433,20 +430,15 @@ impl Engine { /// are not excepted. /// /// Exceptions should be passed directly from HostnameSpecificResources. - /// - /// ## Note - /// The `exceptions` field will be changed to a set, once a new version of - /// PyO3 is released. #[text_signature = "($self, classes, ids, exceptions)"] pub fn hidden_class_id_selectors( &self, classes: Vec, ids: Vec, - exceptions: Vec, + exceptions: HashSet, ) -> PyResult> { - let exception_hashset: HashSet = HashSet::from_iter(exceptions); Ok(self .engine - .hidden_class_id_selectors(&classes, &ids, &exception_hashset)) + .hidden_class_id_selectors(&classes, &ids, &exceptions)) } } -- cgit v1.2.3