Implementing typestate
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Wed Sep 16 10:15:54 PDT 2015
On Wednesday, 16 September 2015 at 17:03:14 UTC, Marc Schütz
wrote:
> On Tuesday, 15 September 2015 at 21:44:25 UTC, Freddy wrote:
>> On Tuesday, 15 September 2015 at 17:45:45 UTC, Freddy wrote:
>>> Rust style memory management in a library
>>
>> Wait nevermind about that part, it's harder than I thought.
>
> Yeah, I thought about type-states as a way of implementing
> borrowing, too. I think the biggest difficulty is that the
> state of one object (the owner) can be affected by what happens
> in other objects (i.e., it becomes mutable again when those are
> destroyed).
If the borrowed reference itself follows move semantics, can't
you just require it to be swallowed by it's origin as the "close"
operation?
pseudocode:
File<Open> f = open();
(File<OpenLending> f, FileRef<Ready> r) = f.borrow();
dostuff(r);
(File<Open> f, FileRef<Void> r) = f.unborrow(r);
File<Closed> f = f.close()
More information about the Digitalmars-d
mailing list