From 6c9a85f222c66ba5fc3f3080b621999b1423281e Mon Sep 17 00:00:00 2001 From: Smitty Date: Wed, 13 Nov 2024 02:19:41 -0500 Subject: [PATCH] Allow creating Oid from a u32 in a const context (#1943) This adds a `const fn` to create an `Oid` from a `u32`. `Oid::from_u32_unchecked` is the only way to do that currently, but it's deprecated and its successor `From::from` is non-const. --- pgrx-pg-sys/src/submodules/oids.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pgrx-pg-sys/src/submodules/oids.rs b/pgrx-pg-sys/src/submodules/oids.rs index c86129bde5..013b0ec0eb 100644 --- a/pgrx-pg-sys/src/submodules/oids.rs +++ b/pgrx-pg-sys/src/submodules/oids.rs @@ -67,6 +67,13 @@ impl Oid { Oid(id) } + /// Creates an Oid from an arbitrary u32. + /// + /// This is the same as the [`From::from`] implementation, but available in a `const` context. + pub const fn from_u32(id: u32) -> Oid { + Oid(id) + } + /// Gets an Oid from a u32 if it is a valid builtin declared by Postgres pub const fn from_builtin(id: u32) -> Result { match BuiltinOid::from_u32(id) {