diff --git a/pgrx/src/callconv.rs b/pgrx/src/callconv.rs index 49103fec96..79944aaa93 100644 --- a/pgrx/src/callconv.rs +++ b/pgrx/src/callconv.rs @@ -10,14 +10,15 @@ #![deny(unsafe_op_in_unsafe_fn)] //! Helper implementations for returning sets and tables from `#[pg_extern]`-style functions -use crate::datum::Datum; use crate::datum::{ AnyArray, AnyElement, AnyNumeric, Date, FromDatum, Inet, Internal, Interval, IntoDatum, Json, JsonB, Numeric, PgVarlena, Time, TimeWithTimeZone, Timestamp, TimestampWithTimeZone, UnboxDatum, Uuid, }; +use crate::datum::{BorrowDatum, Datum}; use crate::datum::{Range, RangeSubType}; use crate::heap_tuple::PgHeapTuple; +use crate::layout::PassBy; use crate::nullable::Nullable; use crate::pg_sys; use crate::pgbox::*; @@ -267,6 +268,19 @@ argue_from_datum! { 'fcx; Inet, Internal, Json, JsonB, Uuid, PgRelation } argue_from_datum! { 'fcx; pg_sys::BOX, pg_sys::ItemPointerData, pg_sys::Oid, pg_sys::Point } argue_from_datum! { 'fcx; &'fcx str, &'fcx CStr, &'fcx [u8] } +unsafe impl<'fcx, T> ArgAbi<'fcx> for &T +where + T: BorrowDatum, +{ + unsafe fn unbox_arg_unchecked(arg: Arg<'_, 'fcx>) -> Self { + if let Some(PassBy::Ref) = T::PASS { + unsafe { &*T::point_from(arg.2.value.cast_mut_ptr()) } + } else { + todo!() + } + } +} + /// How to return a value from Rust to Postgres /// /// This bound is necessary to distinguish things which can be returned from a `#[pg_extern] fn`.