diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/format.rs | 24 | ||||
-rw-r--r-- | src/lib.rs | 2 |
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 @@ -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; |