Skip to content

Implement {Arc, Rc}::downcast #1340

Closed
Closed

Description

@apasel422

I think this is possible to do safely, as it is essentially the inverse operation of CoerceUnsized. See an example implementation at https://github.com/apasel422/ref_count/.

Activity

  1. Gankra commented on Oct 27, 2015

    @Gankra
    Contributor

    For those who don't want to dig through some source:

    impl Arc<Any> {
        pub fn downcast<T>(self) -> Result<Arc<T>, Self> where T: Any;
    }
    
  2. glaebhoerl commented on Oct 27, 2015

    @glaebhoerl
    Contributor

    Could we do this generically (one impl, instead of one per smart pointer type) if we had HKT? (And if we don't?)

  3. seanmonstar commented on Oct 27, 2015

    @seanmonstar
    Contributor

    Don't forget OIBITs... impl Arc<Any + send>, impl Arc<Any + Send + Sync>, etc...

  4. apasel422 commented on Oct 28, 2015

    @apasel422
    ContributorAuthor

    @seanmonstar Thanks for pointing that out. Do we need all combinatoric possibilities of {'static, Send, Sync}?

  5. Gankra commented on Oct 28, 2015

    @Gankra
    Contributor

    I believe if proper trait object subtyping (or just coercions...?) was implemented, this would be a non-issue.

  6. mbrubeck commented on Feb 9, 2018

    @mbrubeck
    Contributor

    <Rc<Any>>::downcast was implemented in rust-lang/rust#44273.

    The Arc method hasn't been implemented yet because it needs extra Send or Sync bounds to be useful.

  7. bluss commented on Feb 9, 2018

    @bluss

    What do you think of simply implementing all combinations, instead of us guessing up front which ones are useful? That would be: Arc<Any>, Arc<Any + Send>, Arc<Any + Sync>, Arc<Any + Send + Sync>.

  8. Centril commented on Oct 7, 2018

    @Centril
    Contributor

    This is implemented for both types, so I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions