config/file/source/
string.rs1use std::error::Error;
2
3use crate::{
4 file::source::FileSourceResult,
5 file::{FileSource, FileStoredFormat},
6 Format,
7};
8
9#[derive(Clone, Debug)]
11pub struct FileSourceString(String);
12
13impl<'a> From<&'a str> for FileSourceString {
14 fn from(s: &'a str) -> Self {
15 Self(s.into())
16 }
17}
18
19impl<F> FileSource<F> for FileSourceString
20where
21 F: Format + FileStoredFormat + 'static,
22{
23 fn resolve(
24 &self,
25 format_hint: Option<F>,
26 ) -> Result<FileSourceResult, Box<dyn Error + Send + Sync>> {
27 Ok(FileSourceResult {
28 uri: None,
29 content: self.0.clone(),
30 format: Box::new(format_hint.expect("from_str requires a set file format")),
31 })
32 }
33}