From d47e1b4f7cb4089112673db57bd1ff8692623fe7 Mon Sep 17 00:00:00 2001 From: Matheus Castello Date: Wed, 15 Nov 2023 20:26:32 -0300 Subject: [PATCH] rnet: Maintain support for versions before 1.72 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 --- rnet/Cargo.toml | 1 + rnet/src/std_impls.rs | 6 ++++++ rnet/src/types.rs | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/rnet/Cargo.toml b/rnet/Cargo.toml index b4beda0..4582121 100644 --- a/rnet/Cargo.toml +++ b/rnet/Cargo.toml @@ -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" diff --git a/rnet/src/std_impls.rs b/rnet/src/std_impls.rs index b8890e2..a0a28c7 100644 --- a/rnet/src/std_impls.rs +++ b/rnet/src/std_impls.rs @@ -177,10 +177,16 @@ unsafe impl ToNet for Box { } } +#[rustversion::since(1.72)] fn int_type_id() -> u128 { unsafe { std::mem::transmute(TypeId::of::()) } } +#[rustversion::before(1.72)] +fn int_type_id() -> u64 { + unsafe { std::mem::transmute(TypeId::of::()) } +} + unsafe impl Net for Arc { type Raw = RawOpaqueHandle; diff --git a/rnet/src/types.rs b/rnet/src/types.rs index 5910db7..888c7fc 100644 --- a/rnet/src/types.rs +++ b/rnet/src/types.rs @@ -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, pub type_id: u128, } +#[rustversion::before(1.72)] +pub struct RawOpaqueHandle { + pub ptr: *mut (), + pub drop_fn: Option, + pub type_id: u64, +} + impl Default for RawOpaqueHandle { fn default() -> Self { Self {