summaryrefslogtreecommitdiffstats
path: root/src/file/source/string.rs
blob: cd2089d8c00bb6db0120e96cff81d603b38e63f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use super::{FileFormat, FileSource};
use std::error::Error;

/// Describes a file sourced from a string
#[derive(Clone, Debug)]
pub struct FileSourceString(String);

impl<'a> From<&'a str> for FileSourceString {
    fn from(s: &'a str) -> Self {
        FileSourceString(s.into())
    }
}

impl FileSource for FileSourceString {
    fn resolve(
        &self,
        format_hint: Option<FileFormat>,
    ) -> Result<(Option<String>, String, FileFormat), Box<dyn Error + Send + Sync>> {
        Ok((
            None,
            self.0.clone(),
            format_hint.expect("from_str requires a set file format"),
        ))
    }
}