-
Notifications
You must be signed in to change notification settings - Fork 445
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
Update Replacer to return a Result<_, T> #267
Comments
This honestly seems a bit niche to me, and therefore may not be worth the added API complexity (which is somewhat significant IMO). If you look at the implementation of the Also, note that the I wonder if it would be plausible to change |
I do agree it would complicate the API. I guess my feeling would be then that the Regex:replace operation is only useful in situations where the replace cannot fail or that panic would be a valid response to failure. Otherwise people would always need to implement their own replace operation like replacen does. |
@pixel27 Well, yes. I suspect the vast majority of use cases of |
I think the current API of |
I ran into this as well. I guess nothing stops a small separate crate from implementing this. I don't think it's a good candidate for "implement yourself", because the ask is very generic - Take a replacer that returns a result, and return a result, but hand rolling replacen is some amount of work. It could be added here as Edit: I made a crate for this https://docs.rs/regex_try/0.1.0/regex_try/ |
This is more an enhancement requests. I'm wondering if it makes sense to update the method:
To be
Then update regex Replacer to be:
The issue I ran into when implementing a Replacer was that I wanted to report an error with the replacement. The only way I could do that was have my Replacer implementation have a mutable reference to an Option<_> that I would set if I encountered an error, then in reg_replace check that and return "" because I was going to throw out the result anyway.
It would be nice if I could return an error from reg_replace() that would abort the whole replacement immediately and return the error to the caller. I know this would be a API change and could break existing code so that needs to be taken into consideration.
I'm not adverse to taking a crack at doing this change, if you are not adverse to changing the API, but I'd want to know that this is something you would consider before accepting before attempting it.
The text was updated successfully, but these errors were encountered: