mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Fix syntax highlighting
+6
-6
@@ -112,14 +112,14 @@ for value in values.iter() { // value: &int
|
||||
|
||||
[Phantom types](http://www.haskell.org/haskellwiki/Phantom_type) are types that cannot be constructed at compile time. To express these in rust, zero-variant `enum`s can be used:
|
||||
|
||||
~~~rust
|
||||
```rust
|
||||
enum Open {}
|
||||
enum Closed {}
|
||||
~~~
|
||||
```
|
||||
|
||||
Phantom types are useful for enforcing state at compile time. For example:
|
||||
|
||||
~~~rust
|
||||
```rust
|
||||
struct Door<State>(~str);
|
||||
|
||||
fn close(Door(name): Door<Open>) -> Door<Closed> {
|
||||
@@ -130,9 +130,9 @@ fn open(Door(name): Door<Closed>) -> Door<Open> {
|
||||
Door(name)
|
||||
}
|
||||
|
||||
close(Door::<Open>(~"front")) // ok
|
||||
close(Door::<Closed>(~"front")) // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
|
||||
~~~
|
||||
close(Door::<Open>(~"front")); // ok
|
||||
close(Door::<Closed>(~"front")); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
|
||||
```
|
||||
|
||||
# Contributing to this page
|
||||
|
||||
|
||||
Reference in New Issue
Block a user