Edit the value of this configuration using the provided editFunc, optionally saving if no exceptions are thrown, and optionally rolling back any changes in the case an exception is thrown.
Exactly the same as edit, except with the save parameter set to yes.
Exactly the same as edit, except with the save parameter set to yes, and rollback set to no.
Exactly the same as edit, except with the rollback paramter set to no.
Loads the configuration. This should overwrite any unsaved changes.
Saves the configuration.
// This is mostly a unittest for testing, not as an example, but may as well show it as an example anyway. static struct Conf { string str; int num; } auto config = new InMemoryConfig!Conf(); // Default: Rollback on failure, don't save on success. // First `edit` fails, so no data should be commited. // Second `edit` passes, so data is edited. // Test to ensure only the second `edit` committed changes. assert(config.edit((scope ref v) { v.str = "Hello"; v.num = 420; throw new Exception(""); }) == WasExceptionThrown.yes); assert(config.edit((scope ref v) { v.num = 21; }) == WasExceptionThrown.no); assert(config.value == Conf(null, 21)); // Reset value, check that we didn't actually call `save` yet. config.load(); assert(config.value == Conf.init); // Test editAndSave. Save on success, rollback on failure. // No longer need to test rollback's pass case, as that's now proven to work. config.editAndSave((scope ref v) { v.str = "Lalafell"; }); config.value = Conf.init; config.load(); assert(config.value.str == "Lalafell"); // Reset value config.value = Conf.init; config.save(); // Test editNoRollback, and then we'll have tested the pass & fail cases for saving and rollbacks. config.editNoRollback((scope ref v) { v.str = "Grubby"; throw new Exception(""); }); assert(config.value.str == "Grubby", config.value.str);
The simplest interface for configuration.
This doesn't care about how data is loaded, stored, or saved. It simply provides a bare-bones interface to accessing data, without needing to worry about the nitty-gritty stuff.