Trait RowExtractExt

Source
pub trait RowExtractExt: Sealed {
    // Required methods
    fn extract_once<'row, T>(&'row self) -> T
       where T: Extract<'row>;
    fn extract<'row, T>(
        &'row self,
        columns: &mut Option<<T as Columns>::Columns>,
    ) -> T
       where T: Extract<'row>;
    fn extract_with_columns<'row, T>(
        &'row self,
        columns: &<T as Columns>::Columns,
    ) -> T
       where T: Extract<'row>;
}
Expand description

Extension trait for extracting from a Row.

Required Methods§

Source

fn extract_once<'row, T>(&'row self) -> T
where T: Extract<'row>,

Extracts an instance of T from this Row.

This is equivalent to T::extract_once(self).

§Panics

Panics if Extract::extract_once panics.

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

fn map_user(row: &Row) -> User<'_> {
    row.extract_once()
}
Source

fn extract<'row, T>( &'row self, columns: &mut Option<<T as Columns>::Columns>, ) -> T
where T: Extract<'row>,

Extracts an instance of T from this Row, memorizing the mapping between fields and columns.

This is equivalent to T::extract(columns, self).

§Panics

Panics if Extract::extract panics.

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

fn map_users(rows: &[Row]) -> Vec<User<'_>> {
    let mut columns = None;
    rows.iter().map(|row| row.extract(&mut columns)).collect()
}
Source

fn extract_with_columns<'row, T>( &'row self, columns: &<T as Columns>::Columns, ) -> T
where T: Extract<'row>,

Extracts an instance of T from this Row and a mapping between the fields and columns.

This is equivalent to T::extract_with_columns(columns, self).

§Panics

Panics if Extract::extract_with_columns panics.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl RowExtractExt for Row

Source§

fn extract_once<'row, T: Extract<'row>>(&'row self) -> T

Source§

fn extract<'row, T>( &'row self, columns: &mut Option<<T as Columns>::Columns>, ) -> T
where T: Extract<'row>,

Source§

fn extract_with_columns<'row, T>( &'row self, columns: &<T as Columns>::Columns, ) -> T
where T: Extract<'row>,

Implementors§