summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRadosław Kot <rdkt13@gmail.com>2021-07-31 12:57:55 +0200
committerRadosław Kot <rdkt13@gmail.com>2021-10-23 16:58:41 +0200
commit141ec79beaa217b7d2dd5fb66aaa2806fe035425 (patch)
treee00cf1d45023b824cac7f1c0cfd53cc62c4f80dc /src
parenta78fc37b2eb0b25ce24c3ae8c54f6b33739cf6b6 (diff)
Implement Format for FileFormat
Diffstat (limited to 'src')
-rw-r--r--src/file/format/mod.rs20
-rw-r--r--src/format.rs35
2 files changed, 29 insertions, 26 deletions
diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs
index b4129e1..47b856d 100644
--- a/src/file/format/mod.rs
+++ b/src/file/format/mod.rs
@@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::error::Error;
use crate::map::Map;
-use crate::value::Value;
+use crate::{value::Value, Format};
#[cfg(feature = "toml")]
mod toml;
@@ -95,7 +95,7 @@ impl FileFormat {
#[doc(hidden)]
#[allow(unused_variables)]
pub fn parse(
- self,
+ &self,
uri: Option<&String>,
text: &str,
) -> Result<Map<String, Value>, Box<dyn Error + Send + Sync>> {
@@ -120,3 +120,19 @@ impl FileFormat {
}
}
}
+
+impl Format for FileFormat {
+ fn parse(
+ &self,
+ uri: Option<&String>,
+ text: &str,
+ ) -> Result<HashMap<String, Value>, Box<dyn Error + Send + Sync>> {
+ self.parse(uri, text)
+ }
+}
+
+impl FileExtensions for FileFormat {
+ fn extensions(&self) -> &Vec<&'static str> {
+ self.extensions()
+ }
+}
diff --git a/src/format.rs b/src/format.rs
index d2fe494..9d666c4 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -1,24 +1,11 @@
-use std::{collections::HashMap, error::Error};
-
-use crate::value::Value;
-
-pub trait Format {
- fn parse(
- self,
- uri: Option<&String>,
- text: &str,
- ) -> Result<HashMap<String, Value>, Box<dyn Error + Send + Sync>>;
-}
-
-impl<F> Format for F
-where
- F: Fn(Option<&String>, &str) -> Result<HashMap<String, Value>, Box<dyn Error + Send + Sync>>
-{
- fn parse(
- self,
- uri: Option<&String>,
- text: &str,
- ) -> Result<HashMap<String, Value>, Box<dyn Error + Send + Sync>> {
- self(uri, text)
- }
-} \ No newline at end of file
+use std::{collections::HashMap, error::Error};
+
+use crate::value::Value;
+
+pub trait Format {
+ fn parse(
+ &self,
+ uri: Option<&String>,
+ text: &str,
+ ) -> Result<HashMap<String, Value>, Box<dyn Error + Send + Sync>>;
+}