summaryrefslogtreecommitdiffstats
path: root/src/file/format/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/file/format/mod.rs')
-rw-r--r--src/file/format/mod.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs
new file mode 100644
index 0000000..5c97a7f
--- /dev/null
+++ b/src/file/format/mod.rs
@@ -0,0 +1,60 @@
+use source::Source;
+use value::Value;
+use std::error::Error;
+
+#[cfg(feature = "toml")]
+mod toml;
+
+// #[cfg(feature = "json")]
+// mod json;
+
+// #[cfg(feature = "yaml")]
+// mod yaml;
+
+#[derive(Debug, Clone, Copy)]
+pub enum FileFormat {
+ /// TOML (parsed with toml)
+ #[cfg(feature = "toml")]
+ Toml,
+
+ // /// JSON (parsed with serde_json)
+ // #[cfg(feature = "json")]
+ // Json,
+
+ // /// YAML (parsed with yaml_rust)
+ // #[cfg(feature = "yaml")]
+ // Yaml,
+}
+
+impl FileFormat {
+ // TODO: pub(crate)
+ #[doc(hidden)]
+ pub fn extensions(&self) -> Vec<&'static str> {
+ match *self {
+ #[cfg(feature = "toml")]
+ FileFormat::Toml => vec!["toml"],
+
+ // #[cfg(feature = "json")]
+ // FileFormat::Json => vec!["json"],
+
+ // #[cfg(feature = "yaml")]
+ // FileFormat::Yaml => vec!["yaml", "yml"],
+ }
+ }
+
+ // TODO: pub(crate)
+ #[doc(hidden)]
+ #[allow(unused_variables)]
+ pub fn parse(&self, uri: Option<&String>, text: &str, namespace: Option<&String>) -> Result<Value, Box<Error>> {
+ match *self {
+ #[cfg(feature = "toml")]
+ FileFormat::Toml => toml::parse(uri, text, namespace),
+
+ // #[cfg(feature = "json")]
+ // FileFormat::Json => json::Content::parse(text, namespace),
+
+ // #[cfg(feature = "yaml")]
+ // FileFormat::Yaml => yaml::Content::parse(text, namespace),
+ }
+ }
+}