Hacker News new | ask | show | jobs
by CaptainOfCoit 641 days ago
> You second example (must call a method) is relatively easy with linear types, as they express "must do something with this value".

Interesting, could you possibly share an example on how that would look like in Rust? Haven't come across it yet, and would certainly help with some things.

Lets say we want to make sure if "MyStruct" is ever defined + created, we want to make sure the program somewhere calls "register_struct" with an instance of that struct.

1 comments

Rust does not implement true linear types, only affine, so I believe your parent is mistaken.

You can do a dynamic check to encode this, but that's not super popular. You can also issue a warning, and in theory turn that warning into an error, but it may also trigger on code unrelated to the specific struct you want it to, so I don't think that's a full solution either, and others may use your code without the warning, getting less guarantees.