pub trait FromDatum {
    const NEEDS_TYPID: bool;

    unsafe fn from_datum(
        datum: Datum,
        is_null: bool,
        typoid: Oid
    ) -> Option<Self>Notable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
    L: Layer<S>,
    S: Subscriber

    where
        Self: Sized
; unsafe fn from_datum_in_memory_context(
        memory_context: PgMemoryContexts,
        datum: Datum,
        is_null: bool,
        typoid: Oid
    ) -> Option<Self>Notable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
    L: Layer<S>,
    S: Subscriber

    where
        Self: Sized
, { ... } }
Expand description

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.

Associated Constants

Required methods

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.

Provided methods

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(...)

Implementations on Foreign Types

for pg_sys::Datum

for bool

for "char"

for smallint

for integer

for oid

for bigint

for real

for double precision

for text, varchar

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

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

for cstring

for bytea

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

Implementors

for json

for jsonb

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

for user types