postgres_array

Struct Array

Source
pub struct Array<T> { /* private fields */ }
Expand description

A multi-dimensional array.

Implementations§

Source§

impl<T> Array<T>

Source

pub fn from_parts(data: Vec<T>, dimensions: Vec<Dimension>) -> Array<T>

Creates a new Array from its underlying components.

The data array should be provided in the higher-dimensional equivalent of row-major order.

§Panics

Panics if the number of elements provided does not match the number of elements specified by the dimensions.

Source

pub fn from_vec(data: Vec<T>, lower_bound: i32) -> Array<T>

Creates a new one-dimensional array.

Source

pub fn wrap(&mut self, lower_bound: i32)

Wraps this array in a new dimension of size 1.

For example, the one dimensional array [1, 2] would turn into the two-dimensional array [[1, 2]].

Source

pub fn push(&mut self, other: Array<T>)

Consumes another array, appending it to the top level dimension of this array.

The dimensions of the other array must be the same as the dimensions of this array with the first dimension removed. This includes lower bounds as well as lengths.

For example, if [3, 4] is pushed onto [[1, 2]], the result is [[1, 2], [3, 4]].

§Panics

Panics if the dimensions of the two arrays do not match.

Source

pub fn dimensions(&self) -> &[Dimension]

Returns the dimensions of this array.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over references to the elements of the array in the higher-dimensional equivalent of row-major order.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator over mutable references to the elements of the array in the higher-dimensional equivalent of row-major order.

Source

pub fn into_inner(self) -> Vec<T>

Returns the underlying data vector for this Array in the higher-dimensional equivalent of row-major order.

Trait Implementations§

Source§

impl<T: Clone> Clone for Array<T>

Source§

fn clone(&self) -> Array<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Array<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Display> Display for Array<T>

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, T> FromSql<'de> for Array<T>
where T: FromSql<'de>,

Source§

fn from_sql( ty: &Type, raw: &'de [u8], ) -> Result<Array<T>, Box<dyn Error + Sync + Send>>

Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format. Read more
Source§

fn accepts(ty: &Type) -> bool

Determines if a value of this type can be created from the specified Postgres Type.
Source§

fn from_sql_null(ty: &Type) -> Result<Self, Box<dyn Error + Send + Sync>>

Creates a new value of this type from a NULL SQL value. Read more
Source§

fn from_sql_nullable( ty: &Type, raw: Option<&'a [u8]>, ) -> Result<Self, Box<dyn Error + Send + Sync>>

A convenience function that delegates to from_sql and from_sql_null depending on the value of raw.
Source§

impl<T, I: ArrayIndex> Index<I> for Array<T>

Indexes into the Array, retrieving a reference to the contained value.

Since Arrays can be multi-dimensional, the Index trait is implemented for a variety of index types. In the most generic case, a &[i32] can be used. In addition, a bare i32 as well as tuples of up to 10 i32 values may be used for convenience.

§Panics

Panics if the index does not correspond to an in-bounds element of the Array.

§Examples

let mut array = Array::from_vec(vec![0i32, 1, 2, 3], 0);
assert_eq!(2, array[2]);

array.wrap(0);
array.push(Array::from_vec(vec![4, 5, 6, 7], 0));

assert_eq!(6, array[(1, 2)]);
Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: I) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, I: ArrayIndex> IndexMut<I> for Array<T>

Source§

fn index_mut(&mut self, idx: I) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T: 'a> IntoIterator for &'a Array<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more
Source§

impl<'a, T: 'a> IntoIterator for &'a mut Array<T>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IterMut<'a, T>

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for Array<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter<T>

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq for Array<T>

Source§

fn eq(&self, other: &Array<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> ToSql for Array<T>
where T: ToSql,

Source§

fn to_sql( &self, ty: &Type, w: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Converts the value of self into the binary format of the specified Postgres Type, appending it to out. Read more
Source§

fn accepts(ty: &Type) -> bool

Determines if a value of this type can be converted to the specified Postgres Type.
Source§

fn to_sql_checked( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

An adaptor method used internally by Rust-Postgres. Read more
Source§

fn encode_format(&self, _ty: &Type) -> Format

Specify the encode format
Source§

impl<T: Eq> Eq for Array<T>

Source§

impl<T> StructuralPartialEq for Array<T>

Auto Trait Implementations§

§

impl<T> Freeze for Array<T>

§

impl<T> RefUnwindSafe for Array<T>
where T: RefUnwindSafe,

§

impl<T> Send for Array<T>
where T: Send,

§

impl<T> Sync for Array<T>
where T: Sync,

§

impl<T> Unpin for Array<T>
where T: Unpin,

§

impl<T> UnwindSafe for Array<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> BorrowToSql for T
where T: ToSql,

Source§

fn borrow_to_sql(&self) -> &dyn ToSql

Returns a reference to self as a ToSql trait object.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> FromSqlOwned for T
where T: for<'a> FromSql<'a>,