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 TinyVarVar and TinyVarVarULE #5520

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions utils/zerovec/src/ule/chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ impl CharULE {
Self([u0, u1, u2])
}

/// Converts this [`CharULE`] to a [`char`]. This is equivalent to calling
/// [`AsULE::from_unaligned`]
///
/// See the type-level documentation for [`CharULE`] for more information.
#[inline]
pub fn to_char(self) -> char {
let [b0, b1, b2] = self.0;
// Safe because the bytes of CharULE are defined to represent a valid Unicode scalar value.
unsafe { char::from_u32_unchecked(u32::from_le_bytes([b0, b1, b2, 0])) }
}

impl_ule_from_array!(char, CharULE, Self([0; 3]));
}

Expand Down Expand Up @@ -92,15 +103,7 @@ impl AsULE for char {

#[inline]
fn from_unaligned(unaligned: Self::ULE) -> Self {
// Safe because the bytes of CharULE are defined to represent a valid Unicode scalar value.
unsafe {
Self::from_u32_unchecked(u32::from_le_bytes([
unaligned.0[0],
unaligned.0[1],
unaligned.0[2],
0,
]))
}
unaligned.to_char()
}
}

Expand Down
1 change: 1 addition & 0 deletions utils/zerovec/src/ule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod plain;
mod slices;

pub mod tuple;
pub mod vartuple;
pub use chars::CharULE;
pub use encode::{encode_varule_to_box, EncodeAsVarULE};
pub use multi::MultiFieldsULE;
Expand Down
Loading