toql_core/
from_row.rs

1//! Trait to convert result row into structs.
2use crate::sql_builder::select_stream::Select;
3use std::result::Result;
4
5/// This is implemented by Toql Derive for all dervied structs with generic row and error.
6/// The implementation of primitive types with concrete row and error type must be done by the database crate.
7pub trait FromRow<R, E> {
8    /// Returns the number of selects
9    /// This is needed to advance the iterator and
10    /// the row index.
11    /// The Deserializer needs this information to skip left joins
12    /// that have fields selected but are null.
13    /// Those left joins cause select information in the select stream
14    /// that must be skipped.
15    fn forward<'a, I>(iter: &mut I) -> Result<usize, E>
16    where
17        I: Iterator<Item = &'a Select>,
18        Self: std::marker::Sized;
19
20    /// Read row values into struct, starting from index.
21    /// Advances iter and index
22    /// Returns None for value unselected values or joined entities that have null keys.
23    /// Return Error, if value is selected, but cannot be converted.
24
25    fn from_row<'a, I>(row: &R, index: &mut usize, iter: &mut I) -> Result<Option<Self>, E>
26    where
27        I: Iterator<Item = &'a Select> + Clone,
28        Self: std::marker::Sized;
29}