Skip to content

Commit

Permalink
Allow safe Oid conversions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
workingjubilee committed Nov 3, 2023
1 parent 8424ebc commit b6ce27f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pgrx-pg-sys/src/submodules/oids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -98,6 +99,13 @@ impl fmt::Display for Oid {
}
}

/// De facto available via SPI
impl From<u32> for Oid {
fn from(word: u32) -> Oid {
Oid(word)
}
}

impl From<Oid> for u32 {
fn from(oid: Oid) -> u32 {
oid.0
Expand Down

0 comments on commit b6ce27f

Please sign in to comment.