spider_network_blocker
A Rust library to block ads, trackers, and embeds for networking.
Installation
Add spider_network_blocker to your Cargo project with:
use ;
let xhr_blocked = URL_IGNORE_XHR_TRIE.contains_prefix;
let script_blocked = URL_IGNORE_TRIE.contains_prefix;
Dynamic Block List
Extend your block list at runtime without rebuilding. The DynamicBlockList is fully lock-free — reads are wait-free and writes never block readers.
use DynamicBlockList;
// Start empty or pre-seeded
let blocklist = new;
// Seed from a remote source (replaces all patterns)
let remote_patterns = vec!;
blocklist.seed;
// Extend with additional patterns — no cloning, just appends a new layer
blocklist.extend;
blocklist.extend;
// Lock-free check on the hot path
if blocklist.is_blocked
// After many extends, compact layers into one for lookup efficiency
blocklist.compact;
Sharing across threads
use DynamicBlockList;
use Arc;
let blocklist = new;
// Reader threads — wait-free, no contention
let bl = clone;
spawn;
// Writer thread — builds new layer, atomically swaps
let bl = clone;
spawn;
Contributing
Contributions and improvements are welcome. Feel free to open issues or submit pull requests on the GitHub repository.
License
This project is licensed under the MIT License.