Skip to content

Commit 1b1bc4c

Browse files
committed
Implement byte_size for primitives
1 parent 30779de commit 1b1bc4c

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

libcc2rs/src/reinterpret.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub trait ByteRepr: 'static {
3333
macro_rules! impl_byte_repr {
3434
($ty:ty) => {
3535
impl ByteRepr for $ty {
36+
#[inline]
37+
fn byte_size() -> usize {
38+
std::mem::size_of::<$ty>()
39+
}
3640
#[inline]
3741
fn to_bytes(&self, buf: &mut [u8]) {
3842
buf.copy_from_slice(&self.to_ne_bytes());
@@ -61,6 +65,10 @@ impl_byte_repr!(f32);
6165
impl_byte_repr!(f64);
6266

6367
impl ByteRepr for bool {
68+
#[inline]
69+
fn byte_size() -> usize {
70+
1
71+
}
6472
#[inline]
6573
fn to_bytes(&self, buf: &mut [u8]) {
6674
buf[0] = *self as u8;

0 commit comments

Comments
 (0)