reifydb_value/value/frame/
from_frame.rs1use std::{
5 error,
6 fmt::{self, Display, Formatter},
7};
8
9use super::frame::Frame;
10use crate::value::try_from::FromValueError;
11
12#[derive(Debug, Clone)]
13pub enum FromFrameError {
14 MissingColumn {
15 column: String,
16 struct_name: &'static str,
17 },
18
19 ValueError {
20 column: String,
21 row: usize,
22 error: FromValueError,
23 },
24}
25
26impl Display for FromFrameError {
27 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
28 match self {
29 FromFrameError::MissingColumn {
30 column,
31 struct_name,
32 } => {
33 write!(f, "missing column '{}' required by struct '{}'", column, struct_name)
34 }
35 FromFrameError::ValueError {
36 column,
37 row,
38 error,
39 } => {
40 write!(f, "error extracting column '{}' row {}: {}", column, row, error)
41 }
42 }
43 }
44}
45
46impl error::Error for FromFrameError {}
47
48pub trait FromFrame: Sized {
49 fn from_frame(frame: &Frame) -> Result<Vec<Self>, FromFrameError>;
50}