pub trait Columns {
    type Columns: Unpin + Index<usize, Output = usize>;

    // Required method
    fn columns(row: &Row) -> Self::Columns;
}
Expand description

A type whose fields map to Postgres columns.

This trait is almost always derived with the Columns proc macro:

#[derive(Columns)]
struct User<'a> {
    id: i32,
    name: &'a str,
}

In this case the associated Columns type is [usize; N] where N is the number of fields.

Assume that a Row was created from the following query:

select 'john' user, 123 balance, 1 id;

Then the implementation of Columns for the type User above should return [2, 0] because the id field maps to the third column and the name field maps to the first column.

Required Associated Types§

source

type Columns: Unpin + Index<usize, Output = usize>

The type identifying the columns.

This should always be [usize; N] where N is the number of fields. In a future version of this crate, this field will be replaced by

pub trait Columns {
    const NUM_COLUMNS: usize;
}

Required Methods§

source

fn columns(row: &Row) -> Self::Columns

Returns the mapping from the type’s fields to the columns in a Row.

Implementors§