| 1 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::databaserust-analyzer cargo sqlx-core 0.8.3 database/::Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#; |
| 2 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::errorrust-analyzer cargo sqlx-core 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 3 | |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#; |
| 5 | |
| 6 | pub trait Columnrust-analyzer cargo sqlx-core 0.8.3 column/Column#: 'static + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# { |
| 7 | type Databaserust-analyzer cargo sqlx-core 0.8.3 column/Column#Database#: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#<Columnrust-analyzer cargo sqlx-core 0.8.3 database/Database#Column# = Self>; |
| 8 | |
| 9 | /// Gets the column ordinal. |
| 10 | /// |
| 11 | /// This can be used to unambiguously refer to this column within a row in case more than |
| 12 | /// one column have the same name |
| 13 | fn ordinalrust-analyzer cargo sqlx-core 0.8.3 column/Column#ordinal().(&self) -> usize; |
| 14 | |
| 15 | /// Gets the column name or alias. |
| 16 | /// |
| 17 | /// The column name is unreliable (and can change between database minor versions) if this |
| 18 | /// column is an expression that has not been aliased. |
| 19 | fn namerust-analyzer cargo sqlx-core 0.8.3 column/Column#name().(&self) -> &str; |
| 20 | |
| 21 | /// Gets the type information for the column. |
| 22 | fn type_inforust-analyzer cargo sqlx-core 0.8.3 column/Column#type_info().(&self) -> &<Self::Databaserust-analyzer cargo sqlx-core 0.8.3 column/Column#Database# as Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#>::TypeInforust-analyzer cargo sqlx-core 0.8.3 database/Database#TypeInfo#; |
| 23 | } |
| 24 | |
| 25 | /// A type that can be used to index into a [`Row`] or [`Statement`]. |
| 26 | /// |
| 27 | /// The [`get`] and [`try_get`] methods of [`Row`] accept any type that implements `ColumnIndex`. |
| 28 | /// This trait is implemented for strings which are used to look up a column by name, and for |
| 29 | /// `usize` which is used as a positional index into the row. |
| 30 | /// |
| 31 | /// [`Row`]: crate::row::Row |
| 32 | /// [`Statement`]: crate::statement::Statement |
| 33 | /// [`get`]: crate::row::Row::get |
| 34 | /// [`try_get`]: crate::row::Row::try_get |
| 35 | /// |
| 36 | pub trait ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>: Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# { |
| 37 | /// Returns a valid positional index into the row or statement, [`ColumnIndexOutOfBounds`], or, |
| 38 | /// [`ColumnNotFound`]. |
| 39 | /// |
| 40 | /// [`ColumnNotFound`]: Error::ColumnNotFound |
| 41 | /// [`ColumnIndexOutOfBounds`]: Error::ColumnIndexOutOfBounds |
| 42 | fn indexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#index().(&self, container: &T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>; |
| 43 | } |
| 44 | |
| 45 | impl<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, I: ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<T> + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#> ColumnIndexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#<T> for &'_ I { |
| 46 | #[inline] |
| 47 | fn indexrust-analyzer cargo sqlx-core 0.8.3 column/impl#[`&I`][`ColumnIndex<T>`]index().(&self, row: &T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 48 | (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).indexrust-analyzer cargo sqlx-core 0.8.3 column/ColumnIndex#index().(row) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | #[macro_export] |
| 53 | macro_rules! impl_column_index_for_rowrust-analyzer cargo sqlx-core 0.8.3 column/impl_column_index_for_row! { |
| 54 | ($R:ident) => { |
| 55 | impl $crate::column::ColumnIndex<$R> for usize { |
| 56 | fn index(&self, row: &$R) -> Result<usize, $crate::error::Error> { |
| 57 | let len = $crate::row::Row::len(row); |
| 58 | |
| 59 | if *self >= len { |
| 60 | return Err($crate::error::Error::ColumnIndexOutOfBounds { len, index: *self }); |
| 61 | } |
| 62 | |
| 63 | Ok(*self) |
| 64 | } |
| 65 | } |
| 66 | }; |
| 67 | } |
| 68 | |
| 69 | #[macro_export] |
| 70 | macro_rules! impl_column_index_for_statementrust-analyzer cargo sqlx-core 0.8.3 column/impl_column_index_for_statement! { |
| 71 | ($S:ident) => { |
| 72 | impl $crate::column::ColumnIndex<$S<'_>> for usize { |
| 73 | fn index(&self, statement: &$S<'_>) -> Result<usize, $crate::error::Error> { |
| 74 | let len = $crate::statement::Statement::columns(statement).len(); |
| 75 | |
| 76 | if *self >= len { |
| 77 | return Err($crate::error::Error::ColumnIndexOutOfBounds { len, index: *self }); |
| 78 | } |
| 79 | |
| 80 | Ok(*self) |
| 81 | } |
| 82 | } |
| 83 | }; |
| 84 | } |