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

Utf16String::truncate panics if new_len > self.len() #39

Open
bryal opened this issue Jun 17, 2024 · 0 comments
Open

Utf16String::truncate panics if new_len > self.len() #39

bryal opened this issue Jun 17, 2024 · 0 comments

Comments

@bryal
Copy link

bryal commented Jun 17, 2024

The documentation for Utf16String::truncate says that

If new_len is greater than the string’s current length, this has no effect.

But because of the assertion in that method, this is not true. If new_len is greater than the string's current length, truncate will always panic.

assert!(self.is_char_boundary(new_len));

As a user of the library, I would expect the implementation to conform to the documentation, which also matches the behavior of std::string::String::truncate. No effect would be least surprising, a panic is not. Though, as an alternative, adjusting the documentation to match the current behavior would at least be less surprising than there being a mismatch.

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

1 participant