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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ All notable changes to insta and cargo-insta are documented here.

- Add a new integration test approach for `cargo-insta` and a set of integration tests. #537

- Enable Filters to be created from `IntoIterator` types, rather than just `Vec`s. #570

## 1.39.0

- Fixed a bug in `require_full_match`. #485
Expand Down
10 changes: 7 additions & 3 deletions insta/src/filters.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;
use std::iter::FromIterator;
use std::iter::IntoIterator;

use regex::Regex;

Expand All @@ -10,9 +11,12 @@ pub struct Filters {
rules: Vec<(Regex, String)>,
}

impl<'a> From<Vec<(&'a str, &'a str)>> for Filters {
fn from(value: Vec<(&'a str, &'a str)>) -> Self {
Self::from_iter(value)
impl<'a, I> From<I> for Filters
where
I: IntoIterator<Item = (&'a str, &'a str)>,
{
fn from(value: I) -> Self {
Self::from_iter(value.into_iter())
}
}

Expand Down
Loading