Skip to content

Commit 8931538

Browse files
The crown jewel of this entire exercise
1 parent 450abf0 commit 8931538

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pgrx/src/callconv.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
#![deny(unsafe_op_in_unsafe_fn)]
1111
//! Helper implementations for returning sets and tables from `#[pg_extern]`-style functions
1212
13-
use crate::datum::Datum;
1413
use crate::datum::{
1514
AnyArray, AnyElement, AnyNumeric, Date, FromDatum, Inet, Internal, Interval, IntoDatum, Json,
1615
JsonB, Numeric, PgVarlena, Time, TimeWithTimeZone, Timestamp, TimestampWithTimeZone,
1716
UnboxDatum, Uuid,
1817
};
18+
use crate::datum::{BorrowDatum, Datum};
1919
use crate::datum::{Range, RangeSubType};
2020
use crate::heap_tuple::PgHeapTuple;
21+
use crate::layout::PassBy;
2122
use crate::nullable::Nullable;
2223
use crate::pg_sys;
2324
use crate::pgbox::*;
@@ -267,6 +268,19 @@ argue_from_datum! { 'fcx; Inet, Internal, Json, JsonB, Uuid, PgRelation }
267268
argue_from_datum! { 'fcx; pg_sys::BOX, pg_sys::ItemPointerData, pg_sys::Oid, pg_sys::Point }
268269
argue_from_datum! { 'fcx; &'fcx str, &'fcx CStr, &'fcx [u8] }
269270

271+
unsafe impl<'fcx, T> ArgAbi<'fcx> for &T
272+
where
273+
T: BorrowDatum,
274+
{
275+
unsafe fn unbox_arg_unchecked(arg: Arg<'_, 'fcx>) -> Self {
276+
if let Some(PassBy::Ref) = T::PASS {
277+
unsafe { &*T::point_from(arg.2.value.cast_mut_ptr()) }
278+
} else {
279+
todo!()
280+
}
281+
}
282+
}
283+
270284
/// How to return a value from Rust to Postgres
271285
///
272286
/// This bound is necessary to distinguish things which can be returned from a `#[pg_extern] fn`.

0 commit comments

Comments
 (0)