From b6ce27fd79d5b0f0457808195ec8ddca33ef3841 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 3 Nov 2023 10:31:46 -0700 Subject: [PATCH] Allow safe Oid conversions Simply cast `u32 as i32` and pass it through SPI to do this by other means. While it is an incredibly bad idea to do so, unfortunately that means we cannot rely on the conversion being `unsafe`, as there is no way we would make SPI unsafe. That leaves no persuasive argument for not providing From. --- pgrx-pg-sys/src/submodules/oids.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pgrx-pg-sys/src/submodules/oids.rs b/pgrx-pg-sys/src/submodules/oids.rs index d873eecd9..151b28709 100644 --- a/pgrx-pg-sys/src/submodules/oids.rs +++ b/pgrx-pg-sys/src/submodules/oids.rs @@ -63,6 +63,7 @@ impl Oid { /// nor cite SQL statements for misdemeanors, nor even truly stop you from foolishness. /// Even "trustworthy" is meant here in a similar sense to how raw pointers can be "trustworthy". /// Often, you should still check if it's null. + #[deprecated(since = "0.12.0", note = "safely converts via SPI, use pg_sys::Oid::from(u32)")] pub const unsafe fn from_u32_unchecked(id: u32) -> Oid { Oid(id) } @@ -98,6 +99,13 @@ impl fmt::Display for Oid { } } +/// De facto available via SPI +impl From for Oid { + fn from(word: u32) -> Oid { + Oid(word) + } +} + impl From for u32 { fn from(oid: Oid) -> u32 { oid.0