-
Notifications
You must be signed in to change notification settings - Fork 71
Open
Labels
potential-2.0potential changes for `either` 2.0potential changes for `either` 2.0
Description
Apparently AsRef implementation of Either lacks an "unsized" marker ?Sized on Target. It prevents of implementing AsRef<str> for the Either, for instance.
While default Either doesn't compile (without the marker on playground) ...
extern crate either; // 1.5.0
use either::Either;
fn get_default(s: Option<impl AsRef<str>>) -> impl AsRef<str> {
s.map(Either::Left).unwrap_or_else(|| Either::Right("default"))
}
fn main() {
println!("{}", get_default(None::<String>).as_ref());
println!("{}", get_default(Some("not default")).as_ref());
}... an example with the marker compiles just ok :) with the marker on playground
enum Either2<L, R> {
Left(L),
Right(R),
}
impl<L, R, T: ?Sized> AsRef<T> for Either2<L, R>
where
L: AsRef<T>,
R: AsRef<T>,
{
fn as_ref(&self) -> &T {
match self {
Either2::Left(x) => x.as_ref(),
Either2::Right(x) => x.as_ref(),
}
}
}
fn get_default(s: Option<impl AsRef<str>>) -> impl AsRef<str> {
s.map(Either2::Left)
.unwrap_or_else(|| Either2::Right("default"))
}
fn main() {
println!("{}", get_default(None::<String>).as_ref());
println!("{}", get_default(Some("not default")).as_ref());
}So, my question is: was the ?Sized marker omitted on purpose, or should I make a PR which adds the marker? :)
Metadata
Metadata
Assignees
Labels
potential-2.0potential changes for `either` 2.0potential changes for `either` 2.0