binary-layout icon indicating copy to clipboard operation
binary-layout copied to clipboard

Size constant for fixed size layout without option

Open rluvaton opened this issue 1 year ago • 0 comments

It would be great if we could do

binary_layout!(header_layout, NativeEndian, {
    free_space_start: u16,
    free_space_end: u16,
    total_free_space: u16,
});

pub const HEADER_SIZE: usize = header_layout::FIXED_SIZE

It should be equivalent for:

mem::size_of::<header_layout>()

I can't do:

pub const HEADER_SIZE: usize = header_layout::SIZE.unwrap()

as Option::<T>::unwrap is not yet stable as a const fn`

and I can't

header_layout::total_free_space::OFFSET + header_layout::total_free_space::SIZE

as SIZE return option even for known sizes, and this is not a good solution either because if I add another fields at the end I need to update that as well

For now I just did the following:

pub const HEADER_SIZE: usize = unwrap_field_size(header_layout::SIZE);

But it's internal method...

rluvaton avatar Jul 22 '24 17:07 rluvaton