Skip to content

Commit 27004ac

Browse files
committed
Add fn Sealed::from_le_bytes and #[inline(always)] annotations
1 parent 5ba0f6a commit 27004ac

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/word.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod sealed {
1313
pub trait Sealed: Default + Copy + TryFrom<usize> + Eq + core::hash::Hash {
1414
type Bytes: Sized + AsRef<[u8]>;
1515

16+
fn from_le_bytes(bytes: Self::Bytes) -> Self;
1617
fn to_le_bytes(self) -> Self::Bytes;
1718

1819
fn from_usize(val: usize) -> Self;
@@ -22,13 +23,20 @@ mod sealed {
2223
impl Sealed for u32 {
2324
type Bytes = [u8; 4];
2425

26+
#[inline(always)]
27+
fn from_le_bytes(bytes: Self::Bytes) -> Self {
28+
Self::from_le_bytes(bytes)
29+
}
30+
#[inline(always)]
2531
fn to_le_bytes(self) -> Self::Bytes {
2632
Self::to_le_bytes(self)
2733
}
2834

35+
#[inline(always)]
2936
fn from_usize(val: usize) -> Self {
3037
val.try_into().unwrap()
3138
}
39+
#[inline(always)]
3240
fn into_usize(self) -> usize {
3341
self.try_into().unwrap()
3442
}
@@ -37,13 +45,20 @@ mod sealed {
3745
impl Sealed for u64 {
3846
type Bytes = [u8; 8];
3947

48+
#[inline(always)]
49+
fn from_le_bytes(bytes: Self::Bytes) -> Self {
50+
Self::from_le_bytes(bytes)
51+
}
52+
#[inline(always)]
4053
fn to_le_bytes(self) -> Self::Bytes {
4154
Self::to_le_bytes(self)
4255
}
4356

57+
#[inline(always)]
4458
fn from_usize(val: usize) -> Self {
4559
val.try_into().unwrap()
4660
}
61+
#[inline(always)]
4762
fn into_usize(self) -> usize {
4863
self.try_into().unwrap()
4964
}

0 commit comments

Comments
 (0)