Skip to content

Implement CoerceUnsized for Unique<T> #1343

Closed
@rphmeier

Description

@rphmeier

It's implemented for raw pointers, references, boxes, Rc, Arc, NonZero, and Shared. Is there a specific reason it can't be implemented for Unique?

As it stands, you can't actually reimplement something like Box the same way the standard library does. Somehow, even though a Box is just a wrapper around Unique, it can be coerced to an unsized type due to some compiler magic.

The following is paraphrased from the Box source, but does not compile:

use std::marker::Unsize;
use std::ops::CoerceUnsized;
use std::ptr::Unique;

pub struct MyBox<T: ?Sized>(Unique<T>);

impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<MyBox<U>> for MyBox<T> {}

fn main() { }

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions