4 ms·
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 Tra
by Solarsail 12y ago
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?
- 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.