scraper icon indicating copy to clipboard operation
scraper copied to clipboard

method select should be implemented as a trait

Open joseluis opened this issue 5 years ago • 1 comments

Both Html & ElementRef support the same method select. Having that method implemented as a Trait would allow to create a function that can accept both, and would allow to call that method generically, which doesn't seem to be currently possible.

My current workaround is to call root_element() on Html, to get its ElementRef, which fortunately works even if it's just an html fragment without the <html> tag... Although its description didn't seem to indicate so.

joseluis avatar Dec 11 '20 13:12 joseluis

@joseluis The select methods does not return the same type so I don't think it would make sense to create a trait.

jo1gi avatar Jan 23 '21 19:01 jo1gi

With GATs perhaps this is worth a relook. This could clean up a lot of code duplicating basic select usage with methods that work for both Selector types, as well as make unit tests cleaner, able to just use an &Html from a raw string and get the same result.

RoloEdits avatar Feb 16 '23 04:02 RoloEdits

I think this would introduce additional complexity but not too much benefit (just a few extra lines here and there). Additionally we want to minimise breaking changes wherever possible.

As this wouldn't be a very big change, anyone interested is welcome to propose a pull request (with a few examples) for a new API.

teymour-aldridge avatar Jun 26 '23 09:06 teymour-aldridge