3 ms·
Exactly what you said -- it's not possible to make something that must be used exactly once. See https://gankro.github.io/blah/linear-rust/ https://gankro.githu
by moosingin3space 9y ago
Exactly what you said -- it's not possible to make something that must be used exactly once. See https://gankro.github.io/blah/linear-rust/ https://gankro.github.io/blah/linear-rust/ for a deeper explanation.
- deleted 9y ago[deleted]
- twic 9y agoYou can't make a type that must be used exactly once, but you can often express that requirement in some other way. One technique is to require that some top-level function returns a value of the terminal type; then you can't accidentally abandon a computation part-way through. Here's a silly example: https://play.rust-lang.org/?gist=b875377faa6e22b74ba8661ee106d13d&version=stable https://play.rust-lang.org/?gist=b875377faa6e22b74ba8661ee10... That little DSL lets you make multi-layer burgers, but only where bacon and patties alternate, and there is a bun on the top.