Skip to content

replace object-safe with dyn-compatible in flexibility.md #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/flexibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ needs to make about its arguments.


<a id="c-object"></a>
## Traits are object-safe if they may be useful as a trait object (C-OBJECT)
## Traits are dyn-compatible if they may be useful as a trait object (C-OBJECT)

Trait objects have some significant limitations: methods invoked through a trait
object cannot use generics, and cannot use `Self` except in receiver position.
Expand All @@ -167,25 +167,25 @@ If a trait is meant to be used as an object, its methods should take and return
trait objects rather than use generics.

A `where` clause of `Self: Sized` may be used to exclude specific methods from
the trait's object. The following trait is not object-safe due to the generic
the trait's object. The following trait is not dyn-compatible due to the generic
method.

```rust
trait MyTrait {
fn object_safe(&self, i: i32);
fn dyn_compatible(&self, i: i32);

fn not_object_safe<T>(&self, t: T);
fn not_dyn_compatible<T>(&self, t: T);
}
```

Adding a requirement of `Self: Sized` to the generic method excludes it from the
trait object and makes the trait object-safe.
trait object and makes the trait dyn-compatible.

```rust
trait MyTrait {
fn object_safe(&self, i: i32);
fn dyn_compatible(&self, i: i32);

fn not_object_safe<T>(&self, t: T) where Self: Sized;
fn not_dyn_compatible<T>(&self, t: T) where Self: Sized;
}
```

Expand Down