Skip to content

Generalise filters to support IntoIterator types, not just Vecs#570

Merged
max-sixty merged 1 commit intomitsuhiko:masterfrom
eopb:push-sutvxzqnpmop
Aug 21, 2024
Merged

Generalise filters to support IntoIterator types, not just Vecs#570
max-sixty merged 1 commit intomitsuhiko:masterfrom
eopb:push-sutvxzqnpmop

Conversation

@eopb
Copy link
Copy Markdown
Contributor

@eopb eopb commented Aug 21, 2024

Currently filters must be Vecs:

insta::with_settings!({filters => vec![
    (r"tmp\/\.tmp.*\/", "[TEMPDIR]"),
    (r"var\/.*\/\.tmp.*\/", "[TEMPDIR]"),
]}, { }

However, using an array could be cleaner:

insta::with_settings!({filters => [
    (r"tmp\/\.tmp.*\/", "[TEMPDIR]"),
    (r"var\/.*\/\.tmp.*\/", "[TEMPDIR]"),
]}, { }

And finally, it enables the filters to be extracted into a const:

const FILTERS: [(&'static str, &'static str); 2] = [
    (r"tmp\/\.tmp.*\/", "[TEMPDIR]"),
    (r"var\/.*\/\.tmp.*\/", "[TEMPDIR]"),
];
insta::with_settings!({filters => FILTERS}, { }

@max-sixty
Copy link
Copy Markdown
Collaborator

Thanks @eopb ! Would you be able to add an entry to the changelog?

Currently filters must be `Vec`s:

```rust
insta::with_settings!({filters => vec![
    (r"tmp\/\.tmp.*\/", "[TEMPDIR]"),
    (r"var\/.*\/\.tmp.*\/", "[TEMPDIR]"),
]}, { }
```

However, using an array could be cleaner:

```rust
insta::with_settings!({filters => [
    (r"tmp\/\.tmp.*\/", "[TEMPDIR]"),
    (r"var\/.*\/\.tmp.*\/", "[TEMPDIR]"),
]}, { }
```

And finally, it enables the filters to be extracted into a `const`:

```rust
const FILTERS: [(&'static str, &'static str); 2] = [
    (r"tmp\/\.tmp.*\/", "[TEMPDIR]"),
    (r"var\/.*\/\.tmp.*\/", "[TEMPDIR]"),
];
insta::with_settings!({filters => FILTERS}, { }
```
@eopb eopb force-pushed the push-sutvxzqnpmop branch from 033931c to b786d7c Compare August 21, 2024 22:34
@eopb
Copy link
Copy Markdown
Contributor Author

eopb commented Aug 21, 2024

@max-sixty max-sixty merged commit 9f0017e into mitsuhiko:master Aug 21, 2024
@max-sixty
Copy link
Copy Markdown
Collaborator

Thanks!

@eopb eopb deleted the push-sutvxzqnpmop branch August 22, 2024 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants