pgrx_pg_sys::submodules::datum

Struct Datum

Source
pub struct Datum(/* private fields */);
Expand description

Datum is an abstract value that is effectively a union of all scalar types and all possible pointers in a Postgres context. That is, it is either “pass-by-value” (if the value fits into the platform’s uintptr_t) or “pass-by-reference” (if it does not).

In Rust, it is best to treat this largely as a pointer while passing it around for code that doesn’t care about what the Datum “truly is”. If for some reason it is important to manipulate the address/value without “knowing the type” of the Datum, cast to a pointer and use pointer methods.

Only create Datums from non-pointers when you know you want to pass a value, as it is erroneous for unsafe code to dereference the address of “only a value” as a pointer. It is still a “safe” operation to create such pointers: validity is asserted by dereferencing, or by creating a safe reference such as &T or &mut T. Also be aware that the validity of Datum’s Copy is premised on the same implicit issues with pointers being Copy: while any &T is live, other *mut T must not be used to write to that &T, and &mut T implies no other *mut T even exists outside an &mut T’s borrowing ancestry. It is thus of dubious soundness for Rust code to receive *mut T, create another *mut T, cast the first to &mut T, and then later try to use the second *mut T to write. It is sound for Postgres itself to pass a copied pointer as a Datum to Rust code, then later to mutate that data through its original pointer after Rust creates and releases a &mut T.

For all intents and purposes, Postgres counts as unsafe code that may be relying on you communicating pointers correctly to it. Do not play games with your database.

Implementations§

Source§

impl Datum

Source

pub fn value(self) -> usize

Assume the datum is a value and extract the bits from the memory address, interpreting them as an integer.

Source

pub const fn null() -> Datum

Source

pub fn is_null(self) -> bool

True if the datum is equal to the null pointer.

Source

pub fn cast_mut_ptr<T>(self) -> *mut T

Assume the datum is a pointer and cast it to point to T. It is recommended to explicitly use datum.cast_mut_ptr::<T>().

Trait Implementations§

Source§

impl Clone for Datum

Source§

fn clone(&self) -> Datum

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Datum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> From<*const T> for Datum

Source§

fn from(val: *const T) -> Datum

Converts to this type from the input type.
Source§

impl<T> From<*mut T> for Datum

Source§

fn from(val: *mut T) -> Datum

Converts to this type from the input type.
Source§

impl From<Datum> for usize

Source§

fn from(val: Datum) -> usize

Converts to this type from the input type.
Source§

impl From<Oid> for Datum

Source§

fn from(oid: Oid) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Datum

Source§

fn from(val: bool) -> Datum

Converts to this type from the input type.
Source§

impl From<i16> for Datum

Source§

fn from(val: i16) -> Datum

Converts to this type from the input type.
Source§

impl From<i32> for Datum

Source§

fn from(val: i32) -> Datum

Converts to this type from the input type.
Source§

impl From<i64> for Datum

Source§

fn from(val: i64) -> Datum

Converts to this type from the input type.
Source§

impl From<i8> for Datum

Source§

fn from(val: i8) -> Datum

Converts to this type from the input type.
Source§

impl From<isize> for Datum

Source§

fn from(val: isize) -> Datum

Converts to this type from the input type.
Source§

impl From<u16> for Datum

Source§

fn from(val: u16) -> Datum

Converts to this type from the input type.
Source§

impl From<u32> for Datum

Source§

fn from(val: u32) -> Datum

Converts to this type from the input type.
Source§

impl From<u64> for Datum

Source§

fn from(val: u64) -> Datum

Converts to this type from the input type.
Source§

impl From<u8> for Datum

Source§

fn from(val: u8) -> Datum

Converts to this type from the input type.
Source§

impl From<usize> for Datum

Source§

fn from(val: usize) -> Datum

Converts to this type from the input type.
Source§

impl<T> PartialEq<*mut T> for Datum

Source§

fn eq(&self, other: &*mut T) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<Datum> for *mut T

Source§

fn eq(&self, other: &Datum) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Datum

Source§

fn eq(&self, other: &Datum) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl SqlTranslatable for Datum

Source§

impl TryFrom<Datum> for BuiltinOid

Source§

type Error = NotBuiltinOid

The type returned in the event of a conversion error.
Source§

fn try_from(datum: Datum) -> Result<BuiltinOid, NotBuiltinOid>

Performs the conversion.
Source§

impl TryFrom<NullableDatum> for Datum

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(nd: NullableDatum) -> Result<Datum, ()>

Performs the conversion.
Source§

impl Copy for Datum

Source§

impl StructuralPartialEq for Datum

Auto Trait Implementations§

§

impl Freeze for Datum

§

impl RefUnwindSafe for Datum

§

impl !Send for Datum

§

impl !Sync for Datum

§

impl Unpin for Datum

§

impl UnwindSafe for Datum

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.