[][src]Struct adblock::Engine

pub struct Engine { /* fields omitted */ }

The main object featured in this library. This object holds the adblocker's state, and can be queried to see if a given request should be blocked or not.

Request types

A few of Engine's methods have a field specifying a "resource type", valid examples are:

Implementations

impl Engine[src]

pub fn new(filter_set: FilterSet, optimize: bool) -> Self[src]

Create a new adblocking engine

pub fn check_network_urls(
    &self,
    url: &str,
    source_url: &str,
    request_type: &str
) -> BlockerResult
[src]

Check if the given url—pointing to a resource of type request_type— is blocked, assuming the request is made from the given source_url. Returns an object of type BlockerResult.

Arguments

  • url - The URL of the request to check
  • source_url - The URL from where the request is made
  • request_type - The resource type that the request points to

pub fn check_network_urls_with_hostnames(
    &self,
    url: &str,
    hostname: &str,
    source_hostname: &str,
    request_type: &str,
    third_party_request: Option<bool>
) -> BlockerResult
[src]

Check if a request should be blocked based on the given parameters.

Arguments

  • url - The URL of the request to check
  • hostname - The given url's hostname
  • source_hostname - The hostname of the source URL.
  • request_type - The resource type that the request points to
  • third_party_request - Is the given request to a third-party? Here, None can be given and the engine will figure it out based on the hostname and source_hostname.

pub fn check_network_urls_with_hostnames_subset(
    &self,
    url: &str,
    hostname: &str,
    source_hostname: &str,
    request_type: &str,
    third_party_request: Option<bool>,
    previously_matched_rule: bool,
    force_check_exceptions: bool
) -> BlockerResult
[src]

Check if a request should be blocked based on the given parameters.

Arguments

  • url - The URL of the request to check
  • hostname - The given url's hostname
  • source_hostname - The hostname of the source URL.
  • request_type - The resource type that the request points to
  • third_party_request - Is the given request to a third-party? Here, None can be given and the engine will figure it out based on the hostname and source_hostname.
  • previously_matched_rule - Return a match as long as there are no exceptions
  • force_check_exceptions - Check exceptions even if no other rule matches

pub fn serialize<'p>(&mut self, py: Python<'p>) -> PyResult<&'p PyBytes>[src]

Serialize this blocking engine to bytes. They can then be deserialized using deserialize() to get the same engine again.

pub fn serialize_to_file(&mut self, file: &str) -> PyResult<()>[src]

Serialize this blocking engine to a file. The file can then be deserialized using deserialize_from_file() to get the same engine again.

pub fn deserialize(&mut self, serialized: &[u8]) -> PyResult<()>[src]

Deserialize a blocking engine from bytes produced with serialize().

pub fn deserialize_from_file(&mut self, file: &str) -> PyResult<()>[src]

Deserialize a blocking engine from file produced with serialize_to_file().

pub fn filter_exists(&self, filter: &str) -> bool[src]

Checks if the given filter exists in the blocking engine.

pub fn use_tags(&mut self, tags: Vec<&str>)[src]

Sets this engine's tags to be only the ones provided in tags.

Tags can be used to cheaply enable or disable network rules with a corresponding $tag option.

pub fn enable_tags(&mut self, tags: Vec<&str>)[src]

Sets this engine's tags to additionally include the ones provided in tags.

Tags can be used to cheaply enable or disable network rules with a corresponding $tag option.

pub fn disable_tags(&mut self, tags: Vec<&str>)[src]

Sets this engine's tags to no longer include the ones provided in tags.

Tags can be used to cheaply enable or disable network rules with a corresponding $tag option.

pub fn tag_exists(&self, tag: &str) -> bool[src]

Checks if a given tag exists in this engine.

Tags can be used to cheaply enable or disable network rules with a corresponding $tag option.

pub fn url_cosmetic_resources(&self, url: &str) -> UrlSpecificResources[src]

Returns a set of cosmetic filter resources required for a particular url. Once this has been called, all CSS ids and classes on a page should be passed to hidden_class_id_selectors to obtain any stylesheets consisting of generic rules.

pub fn hidden_class_id_selectors(
    &self,
    classes: Vec<String>,
    ids: Vec<String>,
    exceptions: HashSet<String>
) -> PyResult<Vec<String>>
[src]

If any of the provided CSS classes or ids could cause a certain generic CSS hide rule (i.e. { display: none !important; }) to be required, this method will return a list of CSS selectors corresponding to rules referencing those classes or ids, provided that the corresponding rules are not excepted.

Exceptions should be passed directly from UrlSpecificResources.

Trait Implementations

impl<'a> ExtractExt<'a> for &'a Engine[src]

type Target = PyRef<'a, Engine>

impl<'a> ExtractExt<'a> for &'a mut Engine[src]

type Target = PyRefMut<'a, Engine>

impl HasMethodsInventory for Engine[src]

type Methods = Pyo3MethodsInventoryForEngine

impl HasProtoRegistry for Engine[src]

impl IntoPy<PyObject> for Engine[src]

impl PyClass for Engine[src]

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it's PyDict. Read more

impl PyClassAlloc for Engine[src]

impl PyClassSend for Engine[src]

type ThreadChecker = ThreadCheckerStub<Engine>

impl PyTypeInfo for Engine[src]

type Type = Engine

Type of objects to store in PyObject struct

type BaseType = PyAny

Base class

type Layout = PyCell<Self>

Layout

type BaseLayout = PyCellBase<PyAny>

Layout of Basetype.

type Initializer = PyClassInitializer<Self>

Initializer for layout

type AsRefTarget = PyCell<Self>

Utility type to make AsPyRef work

Auto Trait Implementations

impl RefUnwindSafe for Engine

impl Send for Engine

impl Sync for Engine

impl Unpin for Engine

impl UnwindSafe for Engine

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> FromPy<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> IntoPy<U> for T where
    U: FromPy<T>, 
[src]

impl<T> PyClassAlloc for T where
    T: PyTypeInfo + PyClassWithFreeList
[src]

impl<T> PyMethods for T where
    T: HasMethodsInventory, 
[src]

impl<T> PyProtoMethods for T where
    T: HasProtoRegistry, 
[src]

impl<T> PyTypeObject for T where
    T: PyTypeInfo
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.