1 /** Object Data Persistence.
2     See_Also: https://stackoverflow.com/questions/20932921/automatic-object-persistence-in-d/20934647?noredirect=1#20934647
3 */
4 module nxt.persist;
5 
6 /// Persistent storage of variables of type `T`.
7 struct persistent(T, string file = __FILE__, size_t line = __LINE__)
8 {
9     T store;
10     alias store this;
11 
12     @disable this();    // require an initializer
13 
14     // with the initializer
15     this(T t)
16     {
17         // if it is in the file, we should load it here
18         // else...
19         store = t;
20     }
21 
22     ~this()
23     {
24         import std.stdio : writeln;
25         // you should actually save it to the file. TODO Import file and
26         // calculate its sha1 all at compile-time!
27         // TODO Save store, " as key ", file,":",line);
28     }
29 }
30 
31 unittest
32 {
33     persistent!int x = 10;
34 }