Skip to content

Commit 2d23669

Browse files
committed
Use of the type in interfaces
1 parent c5b23c3 commit 2d23669

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

doc/tutorial.md

+12
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,18 @@ Note that functions do not explicitly have the type parameters that
25082508
are provided by the iface. It will cause a compile-time error if you
25092509
include them in the iface or impl.
25102510
2511+
## Use of the type `self` in interfaces
2512+
2513+
Interfaces may use `self` as a type where the implementation uses its
2514+
own type. This defines an interface for testing equality of a type with
2515+
itself:
2516+
2517+
~~~~
2518+
iface eq {
2519+
fn equals(other: self) -> bool;
2520+
}
2521+
~~~~
2522+
25112523
## Casting to an interface type
25122524
25132525
The above allows us to define functions that polymorphically act on

0 commit comments

Comments
 (0)