Skip to content

Commit

Permalink
Update text/0000-dyno.md
Browse files Browse the repository at this point in the history
Co-authored-by: teor <teor@riseup.net>
  • Loading branch information
yaahc and teor2345 committed Dec 2, 2021
1 parent f8626e1 commit d516750
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion text/0000-dyno.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Each of these approaches has significant downsides: adding methods to traits lea

`provide_any` could be a module inside `any` rather than a sibling (it could then be renamed to `provide` or `provider`).

There are numerous ways to tweak the API of a module like `provide_any`. The dyno and object-provider crates provide two such examples. There are many others, for example providing more patterns of types without requiring tags, not providing any common type patterns (i.e., always requiring tags), not exposing tags at all, etc.
There are numerous ways to tweak the API of a module like `provide_any`. The `dyno` and `object-provider` crates provide two such examples. There are many others, for example providing more patterns of types without requiring tags, not providing any common type patterns (i.e., always requiring tags), not exposing tags at all, etc.

One hazard that must be avoided with such tweaks is that the API must distinguish between reference types with a `'static` lifetime and value types (with no lifetimes), either by using type tags or by having separate mechanisms for handling references and values. If this is done improperly, the API could be unsound. As an example, consider an API which lets an object provide a reference with type `&'a str` (where `'a` is the lifetime of some local scope), then a caller requests an object of type `&'static str` using an API designed for values (possible because that type satisfies the `'static` bound). Without some care, it is possible for the two types to be confused (because the lifetime is not reflected in the type tag or `TypeId`) and for the `&'a str` to be returned with the wrong lifetime. I believe this is not possible in the current proposal, but was possible in an earlier, more ergonomic iteration.

Expand Down

0 comments on commit d516750

Please sign in to comment.