[][src]Trait pgx::datum::FromDatum

pub trait FromDatum {
    pub unsafe fn from_datum(
        datum: Datum,
        is_null: bool,
        typoid: Oid
    ) -> Option<Self>
    where
        Self: Sized
; pub unsafe fn from_datum_in_memory_context(
        mut memory_context: PgMemoryContexts,
        datum: Datum,
        is_null: bool,
        typoid: Oid
    ) -> Option<Self>
    where
        Self: Sized
, { ... } }

Convert a (pg_sys::Datum, is_null:bool, type_oid:pg_sys::Oid) tuple into a Rust type

Default implementations are provided for the common Rust types.

If implementing this, also implement IntoDatum for the reverse conversion.

Required methods

pub unsafe fn from_datum(
    datum: Datum,
    is_null: bool,
    typoid: Oid
) -> Option<Self> where
    Self: Sized
[src]

Safety

This method is inherently unsafe as the datum argument can represent an arbitrary memory address in the case of pass-by-reference Datums. Referencing that memory address can cause Postgres to crash if it's invalid.

If the (datum, is_null) tuple comes from Postgres, it's generally okay to consider this a safe call (ie, wrap it in unsafe {}) and move on with life.

If, however, you're providing an arbitrary datum value, it needs to be considered unsafe and that unsafeness should be propagated through your API.

Loading content...

Provided methods

pub unsafe fn from_datum_in_memory_context(
    mut memory_context: PgMemoryContexts,
    datum: Datum,
    is_null: bool,
    typoid: Oid
) -> Option<Self> where
    Self: Sized
[src]

Default implementation switched to the specified memory context and then simply calls From::from_datum(...) from within that context.

For certain Datums (such as &str), this is likely not enough and this function should be overridden in the type's trait implementation.

The intent here is that the returned Rust type, which might be backed by a pass-by-reference Datum, be copied into the specified memory context, and then the Rust type constructed from that pointer instead.

Safety

Same caveats as From::from_datum(...)

Loading content...

Implementations on Foreign Types

impl<T: FromDatum> FromDatum for Vec<T>[src]

impl<T: FromDatum> FromDatum for Vec<Option<T>>[src]

impl FromDatum for Datum[src]

for pg_sys::Datum

impl FromDatum for bool[src]

for bool

impl FromDatum for i8[src]

for "char"

impl FromDatum for i16[src]

for smallint

impl FromDatum for i32[src]

for integer

impl FromDatum for u32[src]

for oid

impl FromDatum for i64[src]

for bigint

impl FromDatum for f32[src]

for real

impl FromDatum for f64[src]

for double precision

impl<'a> FromDatum for &'a str[src]

for text, varchar

impl FromDatum for String[src]

for text, varchar, or any pg_sys::varlena-based type

This returns a copy, allocated and managed by Rust, of the underlying varlena Datum

impl FromDatum for char[src]

impl<'a> FromDatum for &'a CStr[src]

for cstring

impl<'a> FromDatum for &'a [u8][src]

for bytea

impl FromDatum for Vec<u8>[src]

impl FromDatum for ()[src]

for NULL -- always converts to a None, even if the is_null argument is false

impl FromDatum for BOX[src]

impl FromDatum for Point[src]

impl FromDatum for ItemPointerData[src]

impl<A, B> FromDatum for (Option<A>, Option<B>) where
    A: FromDatum + IntoDatum,
    B: FromDatum + IntoDatum
[src]

impl<A, B, C> FromDatum for (Option<A>, Option<B>, Option<C>) where
    A: FromDatum + IntoDatum,
    B: FromDatum + IntoDatum,
    C: FromDatum + IntoDatum
[src]

Loading content...

Implementors

impl FromDatum for AnyArray[src]

impl FromDatum for AnyElement[src]

impl FromDatum for Date[src]

impl FromDatum for Inet[src]

impl FromDatum for Json[src]

for json

impl FromDatum for JsonB[src]

for jsonb

impl FromDatum for JsonString[src]

for json types to be represented as a wholly-owned Rust String copy

This returns a copy, allocated and managed by Rust, of the underlying varlena Datum

impl FromDatum for Numeric[src]

impl FromDatum for Time[src]

impl FromDatum for TimeWithTimeZone[src]

impl FromDatum for Timestamp[src]

impl FromDatum for TimestampWithTimeZone[src]

impl FromDatum for PgRelation[src]

impl<'a, T: FromDatum> FromDatum for Array<'a, T>[src]

impl<'de, T> FromDatum for T where
    T: PostgresType + Deserialize<'de>, 
[src]

impl<T> FromDatum for Internal<T>[src]

impl<T> FromDatum for PgVarlena<T> where
    T: Copy + Sized
[src]

impl<T> FromDatum for PgBox<T>[src]

for user types

Loading content...