1 use std::error::Error; 2 3 use crate::{ 4 file::source::FileSourceResult, 5 file::{FileSource, FileStoredFormat}, 6 Format, 7 }; 8 9 /// Describes a file sourced from a string 10 #[derive(Clone, Debug)] 11 pub struct FileSourceString(String); 12 13 impl<'a> From<&'a str> for FileSourceString { from(s: &'a str) -> Self14 fn from(s: &'a str) -> Self { 15 Self(s.into()) 16 } 17 } 18 19 impl<F> FileSource<F> for FileSourceString 20 where 21 F: Format + FileStoredFormat + 'static, 22 { resolve( &self, format_hint: Option<F>, ) -> Result<FileSourceResult, Box<dyn Error + Send + Sync>>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 } 34