Skip to content

Commit

Permalink
The crown jewel of this entire exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Sep 11, 2024
1 parent 450abf0 commit 8931538
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pgrx/src/callconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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`.
Expand Down

0 comments on commit 8931538

Please sign in to comment.