Skip to content

Commit

Permalink
rnet: Maintain support for versions before 1.72
Browse files Browse the repository at this point in the history
TypeIds are now 128 bits, so we need to use a different type for
`RawOpaqueHandle` depending on the rust version.

Signed-off-by: Matheus Castello <[email protected]>
  • Loading branch information
microhobby committed Nov 15, 2023
1 parent f20660d commit d47e1b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions rnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ linkme = "0.2.7"
rnet-macros = { version = "0.3.0", path = "../rnet-macros" }
uuid = { version = "0.8.2", optional = true }
chrono = { version = "0.4.19", optional = true }
rustversion = "1.0.14"
6 changes: 6 additions & 0 deletions rnet/src/std_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,16 @@ unsafe impl<T: ToNet> ToNet for Box<T> {
}
}

#[rustversion::since(1.72)]
fn int_type_id<T: 'static>() -> u128 {
unsafe { std::mem::transmute(TypeId::of::<T>()) }
}

#[rustversion::before(1.72)]
fn int_type_id<T: 'static>() -> u64 {
unsafe { std::mem::transmute(TypeId::of::<T>()) }
}

unsafe impl<T: Send + Sync + 'static> Net for Arc<T> {
type Raw = RawOpaqueHandle;

Expand Down
8 changes: 8 additions & 0 deletions rnet/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ impl Default for RawSlice {

#[derive(Copy, Clone)]
#[repr(C)]
#[rustversion::since(1.72)]
pub struct RawOpaqueHandle {
pub ptr: *mut (),
pub drop_fn: Option<unsafe extern "C" fn(ptr: *mut ())>,
pub type_id: u128,
}

#[rustversion::before(1.72)]
pub struct RawOpaqueHandle {
pub ptr: *mut (),
pub drop_fn: Option<unsafe extern "C" fn(ptr: *mut ())>,
pub type_id: u64,
}

impl Default for RawOpaqueHandle {
fn default() -> Self {
Self {
Expand Down

0 comments on commit d47e1b4

Please sign in to comment.