use std::path::PathBuf;
use crate::options::FormatKind;
use crate::{Value, ser};
#[derive(Debug, Clone, PartialEq)]
pub enum Source {
Folder(PathBuf),
File(PathBuf),
String {
format: FormatKind,
content: String,
},
Value(std::result::Result<Value, String>),
}
impl Source {
pub fn folder(path: impl Into<PathBuf>) -> Self {
Source::Folder(path.into())
}
pub fn file(path: impl Into<PathBuf>) -> Self {
Source::File(path.into())
}
pub fn string(format: impl Into<FormatKind>, content: impl Into<String>) -> Self {
Source::String {
format: format.into(),
content: content.into(),
}
}
pub fn value(value: impl serde::Serialize) -> Self {
Source::Value(
value
.serialize(ser::ValueSerializer)
.map_err(|e| e.to_string()),
)
}
}