use std::collections::HashMap;
use crate::{ResponsePath, ResponseValue, Responses, SurveyDefinition};
pub trait Survey: Sized {
fn survey() -> SurveyDefinition;
fn from_responses(responses: &Responses) -> Self;
fn validate_field(
value: &ResponseValue,
responses: &Responses,
path: &ResponsePath,
) -> Result<(), String>;
fn validate_all(_responses: &Responses) -> HashMap<ResponsePath, String> {
HashMap::new()
}
}
pub trait SurveyBackend {
type Error: Into<anyhow::Error>;
fn collect(
&self,
definition: &SurveyDefinition,
validate: &dyn Fn(&ResponseValue, &Responses, &ResponsePath) -> Result<(), String>,
) -> Result<Responses, Self::Error>;
}