From 5eb013f798baf19e06bd8139ed78a560d19024e3 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 3 Nov 2023 10:37:41 -0700 Subject: [PATCH] Remove unsafeties for Oid conversions --- pgrx/src/datum/from.rs | 2 +- pgrx/src/pgbox.rs | 2 +- pgrx/src/rel.rs | 4 ++-- pgrx/src/tupdesc.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pgrx/src/datum/from.rs b/pgrx/src/datum/from.rs index 9e53c8ae61..ff951f3ea5 100644 --- a/pgrx/src/datum/from.rs +++ b/pgrx/src/datum/from.rs @@ -199,7 +199,7 @@ impl FromDatum for pg_sys::Oid { .value() .try_into() .ok() - .map(|uint| unsafe { pg_sys::Oid::from_u32_unchecked(uint) }) + .map(|uint: u32| pg_sys::Oid::from(uint)) } } } diff --git a/pgrx/src/pgbox.rs b/pgrx/src/pgbox.rs index 139deb5737..aa720d0412 100644 --- a/pgrx/src/pgbox.rs +++ b/pgrx/src/pgbox.rs @@ -73,7 +73,7 @@ use std::ptr::NonNull; /// use pgrx::prelude::*; /// /// pub fn do_something() { -/// # let example_rel_oid = |i| { unsafe { pg_sys::Oid::from_u32_unchecked(i) } }; +/// # let example_rel_oid = |i| pg_sys::Oid::from(i); /// // open a relation and project it as a pg_sys::Relation /// let relid: pg_sys::Oid = example_rel_oid(42); /// let lockmode = pg_sys::AccessShareLock as i32; diff --git a/pgrx/src/rel.rs b/pgrx/src/rel.rs index 9a9ff01259..2cd2f9c830 100644 --- a/pgrx/src/rel.rs +++ b/pgrx/src/rel.rs @@ -208,7 +208,7 @@ impl PgRelation { /// /// ```rust,no_run /// use pgrx::{PgRelation, pg_sys}; - /// # let example_pg_class_oid = |i| { unsafe { pg_sys::Oid::from_u32_unchecked(i) } }; + /// # let example_pg_class_oid = |i| pg_sys::Oid::from(i); /// let oid = example_pg_class_oid(42); // a valid pg_class "oid" value /// let relation = unsafe { PgRelation::from_pg(pg_sys::RelationIdGetRelation(oid) ) }; /// let tupdesc = relation.tuple_desc(); @@ -309,7 +309,7 @@ impl FromDatum for PgRelation { None } else { Some(PgRelation::with_lock( - unsafe { pg_sys::Oid::from_u32_unchecked(u32::try_from(datum.value()).ok()?) }, + pg_sys::Oid::from(u32::try_from(datum.value()).ok()?), pg_sys::AccessShareLock as pg_sys::LOCKMODE, )) } diff --git a/pgrx/src/tupdesc.rs b/pgrx/src/tupdesc.rs index 9a5398ee9e..aabd4daf8e 100644 --- a/pgrx/src/tupdesc.rs +++ b/pgrx/src/tupdesc.rs @@ -116,7 +116,7 @@ impl<'a> PgTupleDesc<'a> { /// /// ```rust,no_run /// use pgrx::{pg_sys, PgTupleDesc}; - /// # let example_pg_type_oid = |i| { unsafe { pg_sys::Oid::from_u32_unchecked(i) } }; + /// # let example_pg_type_oid = |i| pg_sys::Oid::from(i); /// let typid = example_pg_type_oid(42); // a valid pg_type Oid /// let typmod = 0; // its corresponding typemod value /// let tupdesc = unsafe { PgTupleDesc::from_pg_is_copy(pg_sys::lookup_rowtype_tupdesc_copy(typid, typmod)) };