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

Add UnvalidatedChar #3444

Merged
merged 7 commits into from
May 22, 2023
Merged

Conversation

skius
Copy link
Member

@skius skius commented May 20, 2023

Fixes #1968

This adds the unvalidated, three-byte char type UnvalidatedChar with AsULE.

It lives next to UnvalidatedStr for now, but it can easily be moved again.

I borrowed some decisions from UnvalidatedStr in regards to the Debug and Serialize implementations:

  • Debug will try to pretty-print but fall back to bytes if invalid
  • Serialize will fail if the data contained in the UnvalidatedChar is invalid

I implemented EqULE because it applies, but from reading other discussions, it seems we want to move away from it? In which case I would remove it.

Furthermore, I was unsure about Ord - I couldn't think of any reasonable total order we could use here that is consistent with <char as Ord>. If we need it, I'm open to suggestions.

Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: good first PR!

/// assert!(matches!(b.try_as_char(), Err(_)));
/// ```
#[inline]
pub fn try_as_char(self) -> Result<char, core::char::CharTryFromError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, here and below: I think this should be "to" instead of "as" since we are moving (copying) the type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed! Do you know why the clippy lint (wrong_self_convention) didn't trigger (for the other two)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had really mixed results with that lint, but @Manishearth might be able to shed some light on how it works

utils/zerovec/src/ule/unvalidated.rs Outdated Show resolved Hide resolved
utils/zerovec/src/ule/unvalidated.rs Outdated Show resolved Hide resolved
utils/zerovec/src/ule/unvalidated.rs Outdated Show resolved Hide resolved
utils/zerovec/src/ule/plain.rs Outdated Show resolved Hide resolved
utils/zerovec/src/ule/unvalidated.rs Outdated Show resolved Hide resolved
utils/zerovec/src/ule/unvalidated.rs Outdated Show resolved Hide resolved
utils/zerovec/src/ule/unvalidated.rs Show resolved Hide resolved
robertbastian
robertbastian previously approved these changes May 22, 2023
utils/zerovec/src/ule/plain.rs Outdated Show resolved Hide resolved
utils/zerovec/src/ule/plain.rs Outdated Show resolved Hide resolved
@robertbastian robertbastian merged commit 2ebf9d1 into unicode-org:main May 22, 2023
23 checks passed
@Manishearth Manishearth mentioned this pull request Sep 21, 2023
13 tasks
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.

Provide a 3-byte type with GIGO convertibility to/from char in zerovec
3 participants