-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Tracking Issue for try_as_dyn #144361
Copy link
Copy link
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-try_as_dyn`#![feature(try_as_dyn)]``#![feature(try_as_dyn)]`S-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
Activity
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-try_as_dyn`#![feature(try_as_dyn)]``#![feature(try_as_dyn)]`S-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
View all comments
Feature gate:
#![feature(try_as_dyn)]This is a tracking issue for the
try_as_dynandtry_as_dyn_mutfunctions.This feature will let us try to turn any value into a
dyn MyTrait. If the value does not implementMyTraitthen we simply returnNoneso that the user can have some default functionality happen instead.We expect to be able to remove many cases of specialization from the compiler and instead perform this kind of downcasting in the bodies of functions that were relying on specialization before.
A simple example could be
Public API
Steps / History
(Remember to update the
S-tracking-*label when checking boxes.)Unresolved Questions
Currently the implementations are in the
anymodule, which can be very confusing as thesedowncastconcepts are for statically known types, while thedowncastconcepts inAnyproper are for dynamic runtime types.try_as_dyn_staticthat has a'staticbound and permits turning e.g. a&&'static strinto a&dyn Traiteven if there is animpl Trait for &'static str, and not a general impl?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩