summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRadosław Kot <rdkt13@gmail.com>2021-07-31 12:29:53 +0200
committerRadosław Kot <rdkt13@gmail.com>2021-10-23 16:58:41 +0200
commita78fc37b2eb0b25ce24c3ae8c54f6b33739cf6b6 (patch)
treee5d00eee37a08884fec785a95a8c8e1b91134e1f /src
parenta960ffe328ae435763f1d43e65dd426718e9f49f (diff)
Add Format trait
Diffstat (limited to 'src')
-rw-r--r--src/format.rs24
-rw-r--r--src/lib.rs2
2 files changed, 26 insertions, 0 deletions
diff --git a/src/format.rs b/src/format.rs
new file mode 100644
index 0000000..d2fe494
--- /dev/null
+++ b/src/format.rs
@@ -0,0 +1,24 @@
+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
diff --git a/src/lib.rs b/src/lib.rs
index 98c90b4..73abfe3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -57,6 +57,7 @@ mod env;
mod error;
mod file;
mod map;
+mod format;
mod path;
mod ser;
mod source;
@@ -69,6 +70,7 @@ pub use crate::env::Environment;
pub use crate::error::ConfigError;
pub use crate::file::{File, FileFormat, FileSourceFile, FileSourceString};
pub use crate::map::Map;
+pub use crate::format::Format;
pub use crate::source::AsyncSource;
pub use crate::source::Source;
pub use crate::value::Value;