rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Add ParseCallbacks::allow_item() and ParseCallbacks::block_item().

Open nicopauss opened this issue 5 months ago • 0 comments

Like allowlist_item and blocklist_item options, add new methods to ParseCallbacks, ParseCallbacks::allow_item() and ParseCallbacks::block_item(), to be able to allow and block items from being generated.

allowlist_* and blocklist_* options work with regexes and are inserted in a RegexSet.

There are two issues with this approach:

  1. In some cases we want to have more flexibility than just using regexes. If we want to have dynamic conditions to allow or block items, using regexes can be limited.
  2. RegexSet scales linearly with the number of elements inserted. This means that if we have a huge number of items that we want to allow or block, regexes and RegexSet are not necessarily the most appropriate data structures.

Using new methods in ParseCallbacks solves these two issues. We can manually decide the appropriate rules and data structure to match the items.

ParseCallbacks::allow_item() and ParseCallbacks::block_item() are always called after the allowlist_* and blocklist_* options, and allow or do not block the items by default respectively.

nicopauss avatar Jul 09 '25 19:07 nicopauss