Type stored in the file
Serialization format ($(SUPPORTEDFORMATS))
Absolute or relative path to the file
Data from the file in the format specified
import std.exception : assertThrown; import std.file : exists, remove; import std.stdio : File; struct TestStruct { string a; } //Write some example files... File("int.yml", "w").write("---\n9"); File("string.json", "w").write(`"test"`); File("struct.yml", "w").write("---\na: b"); scope(exit) { //Clean up when done if ("int.yml".exists) { remove("int.yml"); } if ("string.json".exists) { remove("string.json"); } if ("struct.yml".exists) { remove("struct.yml"); } } //Read examples from respective files assert(fromFile!(uint, YAML)("int.yml") == 9); assert(fromFile!(string, JSON)("string.json") == "test"); assert(fromFile!(TestStruct, YAML)("struct.yml") == TestStruct("b")); //Read examples from respective files using automatic format detection assert(fromFile!uint("int.yml") == 9); assert(fromFile!string("string.json") == "test"); assert(fromFile!TestStruct("struct.yml") == TestStruct("b")); assertThrown("file.obviouslybadextension".fromFile!uint);
Deserializes data from a file.
Files are assumed to be UTF-8 encoded. If no format (or AutoDetect) is specified, an attempt at autodetection is made.
Supports $(SUPPORTEDSTRUCTURES).