-
Notifications
You must be signed in to change notification settings - Fork 61
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
Unsized marker for AsRef #28
Comments
In principle I think it would be fine to have My only hesitation is whether this constitutes a breaking change to expand the scope of the |
I believe it's impossible: playground extern crate either; // 1.5.0
use either::Either;
struct Unsized {
data: [u8],
}
impl<L, R> AsRef<Unsized> for Either<L, R>
where
L: AsRef<Unsized>,
R: AsRef<Unsized>,
{
fn as_ref(&self) -> &Unsized {
match self {
Either::Left(x) => x.as_ref(),
Either::Right(x) => x.as_ref(),
}
}
} produces
I've made an unsized type just to be more specific, but I believe it doesn't matter in this case. |
Your example works with concrete types though: impl AsRef<Unsized> for Either<Box<Unsized>, Box<Unsized>> {
fn as_ref(&self) -> &Unsized {
match self {
Either::Left(x) => x.as_ref(),
Either::Right(x) => x.as_ref(),
}
}
} |
Ah, true! I didn't look that far :( If we allow unsized types in So it's a breaking change potentially 😢 |
I think we could still implement |
Okay, sounds good! Will send a PR |
Btw, isn't it a potential-2.0 change? (i mean adding the |
Sure, I've added the label. |
It's a shame that expanding the blanket |
Apparently
AsRef
implementation ofEither
lacks an "unsized" marker?Sized
onTarget
. It prevents of implementingAsRef<str>
for theEither
, for instance.While default
Either
doesn't compile (without the marker on playground) ...... an example with the marker compiles just ok :) with the marker on playground
So, my question is: was the
?Sized
marker omitted on purpose, or should I make a PR which adds the marker? :)The text was updated successfully, but these errors were encountered: