1use std::io::Error;
2
3use serde::de::DeserializeOwned;
4
5pub enum InputSourceType<'a> {
6 File(&'a str),
7 String(&'a str),
8 Json(serde_json::Value),
9 JsonString(&'a str),
10}
11
12pub trait InputSource {
13 fn get_data(&self) -> Result<Vec<u8>, Error>;
14}
15
16impl<'a> InputSource for InputSourceType<'a> {
17 fn get_data(&self) -> Result<Vec<u8>, Error> {
18 match self {
19 InputSourceType::File(path) => std::fs::read(path),
20 InputSourceType::String(str) => Ok(str.as_bytes().to_vec()),
21 InputSourceType::Json(json_value) => Ok(serde_json::to_vec(json_value)?),
22 InputSourceType::JsonString(json_str) => Ok(json_str.as_bytes().to_vec()),
23 }
24 }
25}
26
27pub trait InputReader<T: DeserializeOwned> {
28 type Properties;
29
30 fn read(source: &dyn InputSource, properties: Self::Properties) -> Result<T, Error>;
31}