Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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/

It'd be great for someone to write a more up-to-date version of this post!



Haven'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?


You 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...


Rust can still do phantom types.

    struct Foo<T>; // `T` is a phantom type parameter.


Phantom 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.


Yes, you can read a bit about collections and how phantom types are used in them http://cglab.ca/~abeinges/blah/rust-btree-case/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: