AsT<X, Y> // where we can do Rc<X> as Rc<Y>

Is there a builtin trait (or can we define a trait) AsT<X, Y> where the condition is that Rc<X> as Rc<Y> compiles.

pub trait AsT<X, Y> {
  my_as(x: Rc<X>) -> Rc<Y> {
    x as Rc<Y>

so I want this AsT to be for all pairs where the code compiles

This code compiles only if Y = dyn Trait and X: Trait. You can implement AsT for each trait you need separately.

1 Like

This definitely answers the question I asked but not the question I intended to ask. :slight_smile:

I think part of the problem here is that under this system, I need to manually enumerate all possible pairs <X, Y.>, whereas I was hoping this information could somehow be auto derived on demand.