pub struct Array<'mcx, T> { /* private fields */ }
Expand description
An array of some type (eg. TEXT[]
, int[]
)
While conceptually similar to a Vec<T>
, arrays are lazy.
Using a Vec<T>
here means each element of the passed array will be eagerly fetched and converted into a Rust type:
use pgrx::prelude::*;
#[pg_extern]
fn with_vec(elems: Vec<String>) {
// Elements all already converted.
for elem in elems {
todo!()
}
}
Using an array, elements are only fetched and converted into a Rust type on demand:
use pgrx::prelude::*;
#[pg_extern]
fn with_vec(elems: Array<String>) {
// Elements converted one by one
for maybe_elem in elems {
let elem = maybe_elem.unwrap();
todo!()
}
}
Implementations§
Source§impl<'mcx, T: UnboxDatum> Array<'mcx, T>
impl<'mcx, T: UnboxDatum> Array<'mcx, T>
Sourcepub fn iter(&self) -> ArrayIterator<'_, T> ⓘ
pub fn iter(&self) -> ArrayIterator<'_, T> ⓘ
Return an iterator of Option<T>
.
Sourcepub fn iter_deny_null(&self) -> ArrayTypedIterator<'_, T> ⓘ
pub fn iter_deny_null(&self) -> ArrayTypedIterator<'_, T> ⓘ
Return an iterator over the Array’s elements.
§Panics
This function will panic when called if the array contains any SQL NULL values.
pub fn get<'arr>(&'arr self, index: usize) -> Option<Option<T::As<'arr>>>
Source§impl<T> Array<'_, T>
impl<T> Array<'_, T>
Sourcepub fn into_array_type(self) -> *const ArrayType
pub fn into_array_type(self) -> *const ArrayType
Rips out the underlying pg_sys::ArrayType
pointer.
Note that Array may have caused Postgres to allocate to unbox the datum,
and this can hypothetically cause a memory leak if so.
Sourcepub fn contains_nulls(&self) -> bool
pub fn contains_nulls(&self) -> bool
Returns true
if this Array
contains one or more SQL “NULL” values
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Source§impl Array<'_, f64>
impl Array<'_, f64>
Sourcepub fn as_slice(&self) -> Result<&[f64], ArraySliceError>
pub fn as_slice(&self) -> Result<&[f64], ArraySliceError>
Returns a slice of f64
s which comprise this Array
.
§Errors
Returns a ArraySliceError::ContainsNulls
error if this Array
contains one or more
SQL “NULL” values. In this case, you’d likely want to fallback to using Array::iter()
.
Source§impl Array<'_, f32>
impl Array<'_, f32>
Sourcepub fn as_slice(&self) -> Result<&[f32], ArraySliceError>
pub fn as_slice(&self) -> Result<&[f32], ArraySliceError>
Returns a slice of f32
s which comprise this Array
.
§Errors
Returns a ArraySliceError::ContainsNulls
error if this Array
contains one or more
SQL “NULL” values. In this case, you’d likely want to fallback to using Array::iter()
.
Source§impl Array<'_, i64>
impl Array<'_, i64>
Sourcepub fn as_slice(&self) -> Result<&[i64], ArraySliceError>
pub fn as_slice(&self) -> Result<&[i64], ArraySliceError>
Returns a slice of i64
s which comprise this Array
.
§Errors
Returns a ArraySliceError::ContainsNulls
error if this Array
contains one or more
SQL “NULL” values. In this case, you’d likely want to fallback to using Array::iter()
.
Source§impl Array<'_, i32>
impl Array<'_, i32>
Sourcepub fn as_slice(&self) -> Result<&[i32], ArraySliceError>
pub fn as_slice(&self) -> Result<&[i32], ArraySliceError>
Returns a slice of i32
s which comprise this Array
.
§Errors
Returns a ArraySliceError::ContainsNulls
error if this Array
contains one or more
SQL “NULL” values. In this case, you’d likely want to fallback to using Array::iter()
.
Source§impl Array<'_, i16>
impl Array<'_, i16>
Sourcepub fn as_slice(&self) -> Result<&[i16], ArraySliceError>
pub fn as_slice(&self) -> Result<&[i16], ArraySliceError>
Returns a slice of i16
s which comprise this Array
.
§Errors
Returns a ArraySliceError::ContainsNulls
error if this Array
contains one or more
SQL “NULL” values. In this case, you’d likely want to fallback to using Array::iter()
.
Source§impl Array<'_, i8>
impl Array<'_, i8>
Sourcepub fn as_slice(&self) -> Result<&[i8], ArraySliceError>
pub fn as_slice(&self) -> Result<&[i8], ArraySliceError>
Returns a slice of i8
s which comprise this Array
.
§Errors
Returns a ArraySliceError::ContainsNulls
error if this Array
contains one or more
SQL “NULL” values. In this case, you’d likely want to fallback to using Array::iter()
.
Trait Implementations§
Source§impl<'fcx, T> ArgAbi<'fcx> for Array<'fcx, T>where
T: ArgAbi<'fcx> + UnboxDatum,
impl<'fcx, T> ArgAbi<'fcx> for Array<'fcx, T>where
T: ArgAbi<'fcx> + UnboxDatum,
Source§unsafe fn unbox_arg_unchecked(arg: Arg<'_, 'fcx>) -> Self
unsafe fn unbox_arg_unchecked(arg: Arg<'_, 'fcx>) -> Self
Source§unsafe fn unbox_nullable_arg(arg: Arg<'_, 'fcx>) -> Nullable<Self>
unsafe fn unbox_nullable_arg(arg: Arg<'_, 'fcx>) -> Nullable<Self>
Source§fn is_virtual_arg() -> bool
fn is_virtual_arg() -> bool
Source§impl<T: UnboxDatum> Debug for Array<'_, T>
impl<T: UnboxDatum> Debug for Array<'_, T>
Source§impl<'a, T: UnboxDatum> FromDatum for Array<'a, T>
impl<'a, T: UnboxDatum> FromDatum for Array<'a, T>
Source§unsafe fn from_polymorphic_datum(
datum: Datum,
is_null: bool,
_typoid: Oid,
) -> Option<Array<'a, T>>
unsafe fn from_polymorphic_datum( datum: Datum, is_null: bool, _typoid: Oid, ) -> Option<Array<'a, T>>
from_datum
for instantiating polymorphic types
which require preserving the dynamic type metadata. Read moreSource§unsafe fn from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
typoid: Oid,
) -> Option<Self>where
Self: Sized,
unsafe fn from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
typoid: Oid,
) -> Option<Self>where
Self: Sized,
FromDatum::from_datum(...)
from within that context. Read moreSource§const GET_TYPOID: bool = false
const GET_TYPOID: bool = false
from_datum
?Source§unsafe fn try_from_datum(
datum: Datum,
is_null: bool,
type_oid: Oid,
) -> Result<Option<Self>, TryFromDatumError>where
Self: IntoDatum,
unsafe fn try_from_datum(
datum: Datum,
is_null: bool,
type_oid: Oid,
) -> Result<Option<Self>, TryFromDatumError>where
Self: IntoDatum,
try_from_datum
is a convenience wrapper around FromDatum::from_datum
that returns a
a Result
around an Option
, as a Datum can be null. It’s intended to be used in
situations where the caller needs to know whether the type conversion succeeded or failed. Read moreSource§unsafe fn try_from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
type_oid: Oid,
) -> Result<Option<Self>, TryFromDatumError>where
Self: IntoDatum,
unsafe fn try_from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
type_oid: Oid,
) -> Result<Option<Self>, TryFromDatumError>where
Self: IntoDatum,
try_from_datum
that switches to the given context to convert from DatumSource§impl<'mcx, T> IntoIterator for Array<'mcx, T>where
for<'arr> T: UnboxDatum<As<'arr> = T> + 'static,
impl<'mcx, T> IntoIterator for Array<'mcx, T>where
for<'arr> T: UnboxDatum<As<'arr> = T> + 'static,
Source§impl<'mcx, T> IntoNullableIterator<<T as UnboxDatum>::As<'mcx>> for &'mcx Array<'mcx, T>where
T: UnboxDatum,
impl<'mcx, T> IntoNullableIterator<<T as UnboxDatum>::As<'mcx>> for &'mcx Array<'mcx, T>where
T: UnboxDatum,
type Iter = NullableArrayIterator<'mcx, T>
fn into_nullable_iter(self) -> Self::Iter
Source§impl<'mcx, T: UnboxDatum> NullableContainer<'mcx, usize, <T as UnboxDatum>::As<'mcx>> for Array<'mcx, T>
impl<'mcx, T: UnboxDatum> NullableContainer<'mcx, usize, <T as UnboxDatum>::As<'mcx>> for Array<'mcx, T>
type Layout = MaybeStrictNulls<BitSliceNulls<'mcx>>
fn get_layout(&'mcx self) -> &'mcx Self::Layout
Source§impl<'mcx, T: UnboxDatum> Serialize for Array<'mcx, T>
impl<'mcx, T: UnboxDatum> Serialize for Array<'mcx, T>
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<T> SqlTranslatable for Array<'_, T>where
T: SqlTranslatable,
impl<T> SqlTranslatable for Array<'_, T>where
T: SqlTranslatable,
fn argument_sql() -> Result<SqlMapping, ArgumentError>
fn return_sql() -> Result<Returns, ReturnsError>
fn type_name() -> &'static str
fn variadic() -> bool
fn optional() -> bool
fn entity() -> FunctionMetadataTypeEntity
Auto Trait Implementations§
impl<'mcx, T> Freeze for Array<'mcx, T>
impl<'mcx, T> !RefUnwindSafe for Array<'mcx, T>
impl<'mcx, T> !Send for Array<'mcx, T>
impl<'mcx, T> !Sync for Array<'mcx, T>
impl<'mcx, T> Unpin for Array<'mcx, T>
impl<'mcx, T> !UnwindSafe for Array<'mcx, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.