[−][src]Trait pgx::datum::FromDatum
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]
datum: Datum,
is_null: bool,
typoid: Oid
) -> Option<Self> where
Self: Sized,
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
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]
mut memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
typoid: Oid
) -> Option<Self> where
Self: Sized,
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
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
pub unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<&'a str>
[src]
pub unsafe fn from_datum_in_memory_context(
mut memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self> where
Self: Sized,
[src]
mut memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self> where
Self: Sized,
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
pub unsafe fn from_datum(
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<&'a [u8]>
[src]
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<&'a [u8]>
pub unsafe fn from_datum_in_memory_context(
mut memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self> where
Self: Sized,
[src]
mut memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self> where
Self: Sized,
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]
pub unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<Self> where
Self: Sized,
[src]
Self: Sized,
impl FromDatum for Point
[src]
pub unsafe fn from_datum(datum: Datum, is_null: bool, _: Oid) -> Option<Self> where
Self: Sized,
[src]
Self: Sized,
impl FromDatum for ItemPointerData
[src]
pub unsafe fn from_datum(
datum: Datum,
is_null: bool,
_typoid: u32
) -> Option<ItemPointerData>
[src]
datum: Datum,
is_null: bool,
_typoid: u32
) -> Option<ItemPointerData>
impl<A, B> FromDatum for (Option<A>, Option<B>) where
A: FromDatum + IntoDatum,
B: FromDatum + IntoDatum,
[src]
A: FromDatum + IntoDatum,
B: FromDatum + IntoDatum,
pub unsafe fn from_datum(
datum: Datum,
is_null: bool,
typoid: Oid
) -> Option<Self> where
Self: Sized,
[src]
datum: Datum,
is_null: bool,
typoid: Oid
) -> Option<Self> where
Self: Sized,
impl<A, B, C> FromDatum for (Option<A>, Option<B>, Option<C>) where
A: FromDatum + IntoDatum,
B: FromDatum + IntoDatum,
C: FromDatum + IntoDatum,
[src]
A: FromDatum + IntoDatum,
B: FromDatum + IntoDatum,
C: FromDatum + IntoDatum,
pub unsafe fn from_datum(
datum: Datum,
is_null: bool,
typoid: Oid
) -> Option<Self> where
Self: Sized,
[src]
datum: Datum,
is_null: bool,
typoid: Oid
) -> Option<Self> where
Self: Sized,
Implementors
impl FromDatum for AnyArray
[src]
impl FromDatum for AnyElement
[src]
pub unsafe fn from_datum(
datum: Datum,
is_null: bool,
typoid: Oid
) -> Option<AnyElement>
[src]
datum: Datum,
is_null: bool,
typoid: Oid
) -> Option<AnyElement>
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
pub unsafe fn from_datum(
datum: Datum,
is_null: bool,
_: Oid
) -> Option<JsonString>
[src]
datum: Datum,
is_null: bool,
_: Oid
) -> Option<JsonString>
impl FromDatum for Numeric
[src]
pub unsafe fn from_datum(
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self> where
Self: Sized,
[src]
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self> where
Self: Sized,
impl FromDatum for Time
[src]
impl FromDatum for TimeWithTimeZone
[src]
pub unsafe fn from_datum(
datum: usize,
is_null: bool,
typoid: u32
) -> Option<TimeWithTimeZone>
[src]
datum: usize,
is_null: bool,
typoid: u32
) -> Option<TimeWithTimeZone>
impl FromDatum for Timestamp
[src]
impl FromDatum for TimestampWithTimeZone
[src]
pub unsafe fn from_datum(
datum: Datum,
is_null: bool,
_typoid: u32
) -> Option<TimestampWithTimeZone>
[src]
datum: Datum,
is_null: bool,
_typoid: u32
) -> Option<TimestampWithTimeZone>
impl FromDatum for PgRelation
[src]
pub unsafe fn from_datum(
datum: Datum,
is_null: bool,
_typoid: u32
) -> Option<PgRelation>
[src]
datum: Datum,
is_null: bool,
_typoid: u32
) -> Option<PgRelation>
impl<'a, T: FromDatum> FromDatum for Array<'a, T>
[src]
impl<'de, T> FromDatum for T where
T: PostgresType + Deserialize<'de>,
[src]
T: PostgresType + Deserialize<'de>,
pub unsafe fn from_datum(
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self>
[src]
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self>
pub unsafe fn from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self>
[src]
memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self>
impl<T> FromDatum for Internal<T>
[src]
impl<T> FromDatum for PgVarlena<T> where
T: Copy + Sized,
[src]
T: Copy + Sized,
pub unsafe fn from_datum(
datum: Datum,
is_null: bool,
_typoid: u32
) -> Option<Self>
[src]
datum: Datum,
is_null: bool,
_typoid: u32
) -> Option<Self>
pub unsafe fn from_datum_in_memory_context(
mut memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self>
[src]
mut memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self>
impl<T> FromDatum for PgBox<T>
[src]
for user types
pub unsafe fn from_datum(
datum: Datum,
is_null: bool,
_: Oid
) -> Option<PgBox<T>>
[src]
datum: Datum,
is_null: bool,
_: Oid
) -> Option<PgBox<T>>
pub unsafe fn from_datum_in_memory_context(
mut memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self> where
Self: Sized,
[src]
mut memory_context: PgMemoryContexts,
datum: usize,
is_null: bool,
_typoid: u32
) -> Option<Self> where
Self: Sized,