Skip to content

Commit

Permalink
Implement AsULE for Script
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain Ireland committed Sep 28, 2021
1 parent ce7504e commit 825b92d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions components/uniset/src/ule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::enum_props::GeneralSubcategory;
use crate::enum_props::{GeneralSubcategory, Script};
use core::convert::TryFrom;
use num_enum::TryFromPrimitiveError;
use zerovec::ule::{AsULE, ULE};
use zerovec::ule::{AsULE, PlainOldULE, ULE};

#[repr(transparent)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
Expand Down Expand Up @@ -53,3 +53,17 @@ unsafe impl ULE for GeneralSubcategoryULE {
unsafe { core::slice::from_raw_parts(data, len) }
}
}

impl AsULE for Script {
type ULE = PlainOldULE<2>;

#[inline]
fn as_unaligned(&self) -> Self::ULE {
PlainOldULE(self.0.to_le_bytes())
}

#[inline]
fn from_unaligned(unaligned: &Self::ULE) -> Self {
Script(u16::from_le_bytes(unaligned.0))
}
}

0 comments on commit 825b92d

Please sign in to comment.