4 ms·
This is a very old post, but you can encode many uses of typestate pretty easily: http://pcwalton.github.io/blog/2012/12/26/typestate-is-dead/ http://pcwalton.g
by aturon 12y ago
This is a very old post, but you can encode many uses of typestate pretty easily: http://pcwalton.github.io/blog/2012/12/26/typestate-is-dead/ http://pcwalton.github.io/blog/2012/12/26/typestate-is-dead/
It'd be great for someone to write a more up-to-date version of this post!
- Solarsail 12y agoHaven't used Rust, but I wonder what you could use in place of the phantom types? Are Traits capable of filling this role? Am I completely misreading what Traits are? Can Rust still do phantom types, and I just can't see them anywhere in the language reference?
- Jweb_Guru 12y agoRust can still do phantom types. struct Foo<T>; // `T` is a phantom type parameter.
- xKingfisher 12y agoYou should still be able to use phantom types with empty traits or enums. Here's an article[0] (admittedly from ~6 months ago), about using phantom types in Servo. [0] https://blog.mozilla.org/research/2014/06/23/static-checking-of-units-in-servo/ https://blog.mozilla.org/research/2014/06/23/static-checking...
- vhbit 12y agoYes, you can read a bit about collections and how phantom types are used in them http://cglab.ca/~abeinges/blah/rust-btree-case/ http://cglab.ca/~abeinges/blah/rust-btree-case/
- vedosity 12y agoPhantom types aren't part of the language because they don't need to be. They're just empty types used as type parameters for structs, where the type parameter isn't actually used as a variable in the struct. It is more of a design pattern than a language feature.