config/file/source/
mod.rs

1pub(crate) mod file;
2pub(crate) mod string;
3
4use std::error::Error;
5use std::fmt::Debug;
6
7use crate::{file::FileStoredFormat, Format};
8
9/// Describes where the [`File`][super::File] is sourced
10pub trait FileSource<T>: Debug + Clone
11where
12    T: Format + FileStoredFormat,
13{
14    fn resolve(
15        &self,
16        format_hint: Option<T>,
17    ) -> Result<FileSourceResult, Box<dyn Error + Send + Sync>>;
18}
19
20#[allow(unnameable_types)] // Unsure if/how to expose this
21pub struct FileSourceResult {
22    pub(crate) uri: Option<String>,
23    pub(crate) content: String,
24    pub(crate) format: Box<dyn Format>,
25}
26
27impl FileSourceResult {
28    pub fn uri(&self) -> &Option<String> {
29        &self.uri
30    }
31
32    pub fn content(&self) -> &str {
33        self.content.as_str()
34    }
35
36    pub fn format(&self) -> &dyn Format {
37        self.format.as_ref()
38    }
39}