|
10 | 10 | #![deny(unsafe_op_in_unsafe_fn)] |
11 | 11 | //! Helper implementations for returning sets and tables from `#[pg_extern]`-style functions |
12 | 12 |
|
13 | | -use crate::datum::Datum; |
14 | 13 | use crate::datum::{ |
15 | 14 | AnyArray, AnyElement, AnyNumeric, Date, FromDatum, Inet, Internal, Interval, IntoDatum, Json, |
16 | 15 | JsonB, Numeric, PgVarlena, Time, TimeWithTimeZone, Timestamp, TimestampWithTimeZone, |
17 | 16 | UnboxDatum, Uuid, |
18 | 17 | }; |
| 18 | +use crate::datum::{BorrowDatum, Datum}; |
19 | 19 | use crate::datum::{Range, RangeSubType}; |
20 | 20 | use crate::heap_tuple::PgHeapTuple; |
| 21 | +use crate::layout::PassBy; |
21 | 22 | use crate::nullable::Nullable; |
22 | 23 | use crate::pg_sys; |
23 | 24 | use crate::pgbox::*; |
@@ -267,6 +268,20 @@ argue_from_datum! { 'fcx; Inet, Internal, Json, JsonB, Uuid, PgRelation } |
267 | 268 | argue_from_datum! { 'fcx; pg_sys::BOX, pg_sys::ItemPointerData, pg_sys::Oid, pg_sys::Point } |
268 | 269 | argue_from_datum! { 'fcx; &'fcx str, &'fcx CStr, &'fcx [u8] } |
269 | 270 |
|
| 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 | + let ptr: *mut u8 = match T::PASS { |
| 277 | + Some(PassBy::Ref) => arg.2.value.cast_mut_ptr(), |
| 278 | + Some(PassBy::Value) => ptr::addr_of!(arg.0.raw_args()[arg.1].value).cast_mut().cast(), |
| 279 | + _ => todo!(), |
| 280 | + }; |
| 281 | + unsafe { &*T::point_from(ptr) } |
| 282 | + } |
| 283 | +} |
| 284 | + |
270 | 285 | /// How to return a value from Rust to Postgres |
271 | 286 | /// |
272 | 287 | /// This bound is necessary to distinguish things which can be returned from a `#[pg_extern] fn`. |
|
0 commit comments