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

The BitSlice example "trim" doesn't work for empty result slices #113

Closed
KarelPeeters opened this issue Mar 24, 2021 · 1 comment
Closed

Comments

@KarelPeeters
Copy link

KarelPeeters commented Mar 24, 2021

Hey! I'm a new user to this crate, and while reading through the docs I noticed that the first example here seems to have a bad edge case when the returned slice should be empty. This can occur if the imput slice was empty or all to_trim. For the empty input the function craches and for the other case a wrong range still containing a value that should be trimmed is returned.

I think the easiest fix is replacing the last two lines of the function body by this:

let back = bits.iter().by_ref().rposition(stop).map_or(0, |p| p + 1);
&bits[front..back]

This is not a very big deal but it's always nice when the examples actually work 🙂.

@myrrlyn myrrlyn closed this as completed in d00b25c Apr 1, 2021
@myrrlyn
Copy link
Collaborator

myrrlyn commented Apr 1, 2021

Embarassing. Your issue was immediately followed by #114, which is also about my difficult relationship with off-by-one errors when walking a slice backwards.

You are correct; thank you for the report.

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

No branches or pull requests

2 participants