Apply a blacklist of extensions to a list of files

I'm stuck for hours on a pretty simple problem is rust.

I have a vector of strings with filename and I would like to use .filter() to get only the files that don't ends_with() any of the blacklist array...

I have no idea why my code doesn't work :

do you know how should I do this please ?


You're printing an iterator, not its result:

Filter { iter: Iter(["truc.png", "machin.php", "test.txt"]) }

To have the filtration really occur, you need to exhaust an iterator in some way. There are two main methods: one is to add the collect::<Vec<_>>() at the end (since you're not assigning the vector to variable, you need the turbofish, otherwise it might be simply collect()), or printing each filtered value by itself by using a for loop.

Yes I know but right now I want to have only "machin.php" in the iterator because "png" and "txt" are in the blacklist
edit: Oh I thought the iterator I printed have the same content of the vector via collect...
Thanks it works like you're telling me ! Sorry and thank you !

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.