Molten
Molten copied to clipboard
Add static "from" methods and allow writing to files
-
Parser::new()
should becomeParser::from()
and accept anything that AsRef's to&str
-
Parser::from_file()
should be added and accept anything that AsRef's toPath
-
TOMLDocument::save_to()
should be added and accept anything that AsRef's toPath
-
TOMLDocument::save()
should be added, it overwrites the source file if the parser was created through theParser::from_file()
method and returns an error otherwise.
The tests will need to be updated to use these new methods
Taking #5 in mind, should Parser::::from()
automatically parse the data? For example, the test in parser.rs line 757, could look like either of these::
let _ = Parser::from(text).parse();
or
let _ = Parser::from(text);
The later feels better/more ergonomic to me.
If you want to make all of the Parser functions private, you could add a from()
and from_file()
onto the TOMLDocument
, and then have the document control when parsing happens. It depends on what shape the API would be for the users.
Actually, from()
and from_file()
could even be free functions, that's how most parsing libraries seem to do it:
extern crate molten;
let doc = molten::from_file("cargo.toml");
Seems like the best solution to me!
I agree. I'm working on it.
Great!
Note that from_file
may have to become from_reader
, otherwise the references in the parsed document will outlive the original file