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
const NEEDS_TYPID: bool
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
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,
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,
L: Layer<S>,
S: Subscriber,
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
sourceimpl FromDatum for Datum
impl FromDatum for Datum
for pg_sys::Datum
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<Datum>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for bool
impl FromDatum for bool
for bool
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<bool>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for i8
impl FromDatum for i8
for "char"
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<i8>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for i16
impl FromDatum for i16
for smallint
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<i16>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for i32
impl FromDatum for i32
for integer
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<i32>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for u32
impl FromDatum for u32
for oid
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<u32>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for i64
impl FromDatum for i64
for bigint
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<i64>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for f32
impl FromDatum for f32
for real
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<f32>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for f64
impl FromDatum for f64
for double precision
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<f64>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl<'a> FromDatum for &'a str
impl<'a> FromDatum for &'a str
for text, varchar
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<&'a str>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
unsafe fn from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
where
Self: Sized,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for String
impl FromDatum for String
for text, varchar, or any pg_sys::varlena
-based type
This returns a copy, allocated and managed by Rust, of the underlying varlena
Datum
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, typoid: Oid) -> Option<String>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for char
impl FromDatum for char
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, typoid: Oid) -> Option<char>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl<'a> FromDatum for &'a CStr
impl<'a> FromDatum for &'a CStr
for cstring
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<&'a CStr>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl<'a> FromDatum for &'a CStr
impl<'a> FromDatum for &'a CStr
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<&'a CStr>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl<'a> FromDatum for &'a [u8]
impl<'a> FromDatum for &'a [u8]
for bytea
const NEEDS_TYPID: bool
unsafe fn from_datum(
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<&'a [u8]>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
unsafe fn from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
where
Self: Sized,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for ()
impl FromDatum for ()
for NULL – always converts to a None
, even if the is_null argument is false
const NEEDS_TYPID: bool
unsafe fn from_datum(_datum: Datum, _is_null: bool, _: Oid) -> Option<()>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for BOX
impl FromDatum for BOX
const NEEDS_TYPID: bool
unsafe fn from_datum(datum: Datum, is_null: bool, _: 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,
L: Layer<S>,
S: Subscriber,
sourceimpl FromDatum for ItemPointerData
impl FromDatum for ItemPointerData
unsafe fn from_datum(
datum: Datum,
is_null: bool,
_typoid: u32
) -> Option<ItemPointerData>ⓘNotable traits for Option<L>impl<L, S> Layer<S> for Option<L> where
L: Layer<S>,
S: Subscriber,
L: Layer<S>,
S: Subscriber,
sourceimpl<A, B> FromDatum for (Option<A>, Option<B>) where
A: FromDatum + IntoDatum,
B: FromDatum + IntoDatum,
impl<A, B> FromDatum for (Option<A>, Option<B>) where
A: FromDatum + IntoDatum,
B: FromDatum + IntoDatum,
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,
L: Layer<S>,
S: Subscriber,
sourceimpl<A, B, C> FromDatum for (Option<A>, Option<B>, Option<C>) where
A: FromDatum + IntoDatum,
B: FromDatum + IntoDatum,
C: FromDatum + IntoDatum,
impl<A, B, C> FromDatum for (Option<A>, Option<B>, Option<C>) where
A: FromDatum + IntoDatum,
B: FromDatum + IntoDatum,
C: FromDatum + IntoDatum,
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,
L: Layer<S>,
S: Subscriber,
Implementors
sourceimpl FromDatum for PgRelation
impl FromDatum for PgRelation
const NEEDS_TYPID: bool
impl FromDatum for AnyArray
impl FromDatum for AnyElement
impl FromDatum for Inet
impl FromDatum for Internal
impl FromDatum for Json
for json
impl FromDatum for JsonB
for jsonb
impl FromDatum for JsonString
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
impl FromDatum for Time
impl FromDatum for TimeWithTimeZone
impl FromDatum for Timestamp
impl FromDatum for TimestampWithTimeZone
impl FromDatum for Uuid
impl<'a, T: FromDatum> FromDatum for Array<'a, T>
impl<'de, T> FromDatum for T where
T: PostgresType + Deserialize<'de>,
sourceimpl<T> FromDatum for PgBox<T, AllocatedByPostgres>
impl<T> FromDatum for PgBox<T, AllocatedByPostgres>
for user types