Manishearth/triomphe

Remove memoffset from dependencies

Nugine opened this issue · 5 comments

I searched the usage of memoffset.
https://github.com/Manishearth/triomphe/search?q=offset_of
I find that there are only three offset_of! and the layout of data structures are stable. So it's easy to replace the macro with simple constants.

Rust layout is absolutely not stable

Though there may be stdlib builtins for offset now

ArcInner and HeaderSlice have the attribute repr(C) so their layouts are stable.

triomphe/src/arc.rs

Lines 36 to 40 in b6a83f6

#[repr(C)]
pub(crate) struct ArcInner<T: ?Sized> {
pub(crate) count: atomic::AtomicUsize,
pub(crate) data: T,
}

triomphe/src/header.rs

Lines 15 to 22 in df0434a

#[repr(C)]
pub struct HeaderSlice<H, T: ?Sized> {
/// The fixed-sized data.
pub header: H,
/// The dynamically-sized data.
pub slice: T,
}

Ah. I would still like to not have to rely on hardcoded constants here

But I think stdlib has ptr_addr_of if you want to get rid of the dep

ptr::addr_of{_mut} are better but they are added since Rust 1.51.0. Do you have a MSRV policy?

Not really no