Skip to content

Commit d0d3448

Browse files
authored
Improve documentation about regex (#2494)
Remove repeating documentation and keep it in a single section.
1 parent fa8dd50 commit d0d3448

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

bindgen/lib.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,27 @@ impl std::fmt::Display for Formatter {
262262
///
263263
/// # Regular expression arguments
264264
///
265-
/// Some [`Builder`] methods like the `allowlist_*` and `blocklist_*` family of methods allow
266-
/// regular expressions as arguments. These regular expressions will be parenthesized and wrapped
267-
/// in `^` and `$`. So if `<regex>` is passed as argument, the regular expression to be stored will
268-
/// be `^(<regex>)$`.
265+
/// Some [`Builder`] methods such as the `allowlist_*` and `blocklist_*` methods allow regular
266+
/// expressions as arguments. These regular expressions will be enclosed in parentheses and
267+
/// anchored with `^` and `$`. So if the argument passed is `<regex>`, the regular expression to be
268+
/// stored will be `^(<regex>)$`.
269+
///
270+
/// As a consequence, regular expressions passed to `bindgen` will try to match the whole name of
271+
/// an item instead of a section of it, which means that to match any items with the prefix
272+
/// `prefix`, the `prefix.*` regular expression must be used.
273+
///
274+
/// Certain methods, like [`Builder::allowlist_function`], use regular expressions over function
275+
/// names. To match C++ methods, prefix the name of the type where they belong followed by an
276+
/// underscore. So if the type `Foo` has a method `bar`, it can be matched with the `Foo_bar`
277+
/// regular expression.
278+
///
279+
/// Additionally, Objective-C interfaces can be matched by prefixing the regular expression with
280+
/// `I`. For example, the `IFoo` regular expression matches the `Foo` interface and the `IFoo_foo`
281+
/// regular expression matches the `foo` method of the `Foo` interface.
269282
///
270283
/// Releases of `bindgen` with a version lesser or equal to `0.62.0` used to accept the wildcard
271284
/// pattern `*` as a valid regular expression. This behavior has been deprecated and the `.*`
272-
/// pattern must be used instead.
285+
/// regular expression must be used instead.
273286
#[derive(Debug, Default, Clone)]
274287
pub struct Builder {
275288
options: BindgenOptions,

bindgen/options/helpers.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ macro_rules! regex_option {
44
($(#[$attrs:meta])* pub fn $($tokens:tt)*) => {
55
$(#[$attrs])*
66
///
7-
/// Regular expressions are supported. To match any items that start with `prefix` use the
8-
/// `"prefix.*"` regular expression.
9-
///
10-
/// Check the [regular expression arguments](./struct.Builder.html#regular-expression-arguments)
11-
/// section and the [regex](https://docs.rs/regex) crate documentation for further
12-
/// information.
7+
/// Regular expressions are supported. Check the [regular expression
8+
/// arguments](./struct.Builder.html#regular-expression-arguments) section and the
9+
/// [regex](https://docs.rs/regex) crate documentation for further information.
1310
pub fn $($tokens)*
1411
};
1512
}

bindgen/options/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ options! {
171171
methods: {
172172
regex_option! {
173173
/// Do not generate any bindings for the given function.
174-
///
175-
/// Methods can be blocklisted by prefixing the name of the type where they belong
176-
/// followed by an underscore. So if the type `Foo` has a method `bar`, it can be
177-
/// blocklisted as `Foo_bar`.
178174
pub fn blocklist_function<T: AsRef<str>>(mut self, arg: T) -> Builder {
179175
self.options.blocklisted_functions.insert(arg);
180176
self
@@ -289,10 +285,6 @@ options! {
289285
regex_option! {
290286
/// Generate bindings for the given function.
291287
///
292-
/// Methods can be allowlisted by prefixing the name of the type where they belong
293-
/// followed by an underscore. So if the type `Foo` has a method `bar`, it can be
294-
/// allowlisted as `Foo_bar`.
295-
///
296288
/// This option is transitive by default. Check the documentation of the
297289
/// [`Builder::allowlist_recursively`] method for further information.
298290
pub fn allowlist_function<T: AsRef<str>>(mut self, arg: T) -> Builder {
@@ -418,7 +410,7 @@ options! {
418410
regex_option! {
419411
/// Mark the given `enum` as a Rust `enum`.
420412
///
421-
/// This means that each variant of the `enum` will be represented as a Rust `enum
413+
/// This means that each variant of the `enum` will be represented as a Rust `enum`
422414
/// variant.
423415
///
424416
/// **Use this with caution**, creating an instance of a Rust `enum` with an

0 commit comments

Comments
 (0)