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

Implement Display trait for string::Match #1172

Closed
wants to merge 1 commit into from

Conversation

volsa
Copy link

@volsa volsa commented Mar 10, 2024

I regularly have to convert matches of a named capture group into a string, which with the current master branch is achieved by capture.as_str().to_string(). This PR implements the Display trait to simplify the given snippet into capture.to_string().

@BurntSushi
Copy link
Member

Display is for user facing output, and there are many ways in which a Match could be formatted for users. Because of that, this trait impl isn't appropriate.

@BurntSushi BurntSushi closed this Mar 10, 2024
@volsa volsa deleted the impl-display branch March 10, 2024 15:18
@volsa
Copy link
Author

volsa commented Mar 10, 2024

Thanks for the feedback! I'm just curious and would like to understand why a user would want to see anything other than the haystack field? Put differently there are only two other fields (start, end) which I reckon are only interesting for debug cases and already covered by the Debug trait hence wouldn't the Display trait be valid for just displaying haystack?

Edit: Is it because of e.g. user facing output like "Haystack: '...'"?

@BurntSushi
Copy link
Member

Offsets might be important to users. Grep for example has options to print offsets. Offsets aren't just for debugging.

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.

None yet

2 participants