Skip to content
This repository was archived by the owner on Oct 9, 2018. It is now read-only.

Commit 121e90a

Browse files
committed
RFC for trait object guidelines
1 parent dc764ed commit 121e90a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

errors/signaling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ parameters beyond their static type.
7777

7878
### For preventable errors, prefer `Result`.
7979

80-
Preventable errors present API designers with a choice:
80+
For preventable errors, API designers have to make a choice:
8181
* Permit erroneous input, return `Result`, and use the `Err` variant to inform
8282
the client of the error.
8383
* Treat erroneous input as a _contract violation_ (i.e., assertion failure) and `fail!`.

features/traits/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
Traits are probably Rust's most complex feature, supporting a wide range of use
44
cases and design tradeoffs. Patterns of trait usage are still emerging.
55

6-
### Know whether a trait will be used as an object. [OPEN]
6+
### Know whether a trait will be used as an object. [RFC]
77

8-
Trait objects have some [significant limitations](objects.md).
8+
Trait objects have some [significant limitations](objects.md): methods
9+
invoked through a trait object cannot use generics, and cannot use
10+
`Self` except in receiver position.
911

10-
When designing a trait, decide early on whether the trait will be used as an
11-
object, in part by considering these limitations.
12+
When designing a trait, decide early on whether the trait will be used
13+
as an [object](objects.md) or as a [bound on generics](generics.md);
14+
the tradeoffs are discussed in each of the linked sections.
15+
16+
If a trait is meant to be used as an object, its methods should take
17+
and return trait objects rather than use generics.
1218

13-
> **[OPEN]** Is there more specific advice we can give here?
1419

1520
### Default methods [OPEN]
1621

0 commit comments

Comments
 (0)