Skip to content

Allow exec* methods to fail with partial matches. #25

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

Closed

Conversation

mrkline
Copy link

@mrkline mrkline commented Jun 12, 2016

Currently, PCRE_ERROR_PARTIAL is bundled with other errors, making
ExecPartialSoft and ExecPartialHard useless. The exec* family of
methods now returns a Result, with two possible error cases:

  • A partial match occurred.
  • Some other error occurred.

This is my first foray into Rust (outside tutorials and toy projects),
so forgive me if anything isn't idiomatic.
I'm happy to fix up the PR as-needed.

Currently, PCRE_ERROR_PARTIAL is bundled with other errors, making
ExecPartialSoft and ExecPartialHard useless. The exec* family of
methods now returns a Result, with two possible error cases:
- A partial match occurred.
- Some other error occurred.

This is my first foray into Rust (outside tutorials and toy projects),
so forgive me if anything isn't idiomatic.
I'm happy to fix up the PR as-needed.
@cadencemarseille
Copy link
Owner

Hello Matt,

Sorry for the delay in responding to this.

I like the idea of supporting PCRE_PARTIAL_HARD and PCRE_PARTIAL_SOFT. Building on your PR, I think that it would be a good idea to get rid of the panic in pcre::detail::pcre_exec(), particularly since it might become commonplace to use the -C panic=abort flag to decrease binary sizes and compilation times.

One thing I am not sure about (and correct me if I am wrong) is that the PR translates the no-match scenario to ExecError::GeneralError, which is a catch-all for all of the errors that pcre_exec() can return. Maybe it would be a good idea to map all of the error values returned by pcre_exec() from the start, so that mapping an additional error code as people request them would not break existing matches of ExecError without a default clause ("non-exhaustive patterns" error).

At one point Rust had an Either enum, but it was removed (see rust-lang/rust#9157). What do you think about creating a custom enum type, say ExecResult, that would have Some(Match), None, and Err variants? This way, the current API of calling is_none() or is_some(), or matching on the result, could be preserved.

Cadence

@mrkline
Copy link
Author

mrkline commented Jul 15, 2016

Sorry for the delay in responding to this.

No worries! Life is busy.

Maybe it would be a good idea to map all of the error values returned by pcre_exec() from the start, so that mapping an additional error code as people request them would not break existing matches of ExecError without a default clause ("non-exhaustive patterns" error).

I think that's the best way forward. I set up GeneralError as a quick proof of concept to see what you guys thought about supporting partial matches.

What do you think about creating a custom enum type, say ExecResult, that would have Some(Match), None, and Err variants?

I'll try that out when I get the chance. Thanks for the feedback!

@mrkline mrkline mentioned this pull request Aug 29, 2016
@mrkline
Copy link
Author

mrkline commented Aug 29, 2016

I finally got around to trying the suggestions above. Closing in favor of #28.

@mrkline mrkline closed this Aug 29, 2016
@mrkline mrkline deleted the allow-partial-matches branch August 29, 2016 02:11
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