Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

eopb
Copy link
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
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
Contributor Author

eopb commented Aug 21, 2024

@max-sixty max-sixty merged commit 9f0017e into mitsuhiko:master Aug 21, 2024
15 checks passed
@max-sixty
Copy link
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