Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Opaque as shorthand for Box<dyn Any + Send> #2640

Merged
merged 3 commits into from
Feb 9, 2021

Conversation

lu-zero
Copy link
Collaborator

@lu-zero lu-zero commented Jan 14, 2021

It makes the code a little tidy and paves the way to add Sync to the traits once rust-lang/rust#80945 lands.

@coveralls
Copy link
Collaborator

coveralls commented Jan 14, 2021

Coverage Status

Coverage increased (+0.3%) to 83.268% when pulling 85fc222 on rust-av:opaque-shorthand into 165b9b5 on xiph:master.

@sdroege
Copy link
Contributor

sdroege commented Jan 15, 2021

It makes the code a little tidy and paves the way to add Sync to the traits once rust-lang/rust#80945 lands.

Or you do this for the time being in your code:

fn downcast<T: Any + Send + Sync>(
    b: Box<dyn Any + Send + Sync>,
) -> Result<Box<T>, Box<dyn Any + Send + Sync>> {
    if b.is::<T>() {
        unsafe {
            let raw: *mut (dyn Any + Send + Sync) = Box::into_raw(b);
            Ok(Box::from_raw(raw as *mut T))
        }
    } else {
        Err(b)
    }
}

Copy link
Contributor

@sdroege sdroege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but is of course an API change

@lu-zero
Copy link
Collaborator Author

lu-zero commented Jan 15, 2021

I slated it for the release 0.5.0.

@lu-zero lu-zero mentioned this pull request Jan 29, 2021
3 tasks
@lu-zero lu-zero merged commit 83b41f8 into xiph:master Feb 9, 2021
@lu-zero lu-zero deleted the opaque-shorthand branch February 9, 2021 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants