Skip to content

Commit

Permalink
Merge pull request #224 from ferrous-systems/dynsafe
Browse files Browse the repository at this point in the history
object safety is now called dyn compatibility
  • Loading branch information
jonathanpallant authored Nov 19, 2024
2 parents 54c0c60 + f2378f8 commit 114d9f3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions training-slides/src/dynamic-dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn main() {
- Plus auto traits, like `Send` and `Sync`
- This trait must fulfill certain conditions

## Rules for object-safe traits (abbreviated)
## Rules for dyn-compatible traits (abbreviated)

- Must not have `Self: Sized`
- No associated constants or GATs
Expand All @@ -98,7 +98,9 @@ fn main() {
- Not use `Self`, only `&self` etc
- Not return `impl Trait`

See [the docs](https://doc.rust-lang.org/reference/items/traits.html#object-safety) for details.
See [the docs](https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility) for details.

Note that these used to be called "object safety" rules before 1.83.

## Performance

Expand All @@ -108,7 +110,7 @@ See <https://godbolt.org/z/cheWrvM45>

## Trait Objects and Closures

Closure traits fulfill object safety rules.
Closure traits are dyn-compatible.

```rust []
fn factory() -> Box<dyn Fn(i32) -> i32> {
Expand Down

0 comments on commit 114d9f3

Please sign in to comment.