Determine if type is Sized through a const fn

Since you're already relying on nightly, you could consider using something like:

#![feature(specialization)]

trait Sizedness {
    const FIXED_SIZE: bool;
}

impl<T : ?Sized> Sizedness for T {
    default
    const FIXED_SIZE: bool = false;
}

impl<T> Sizedness for T {
    const FIXED_SIZE: bool = true;
}

Now, it does rely on the incomplete specialization feature; that being said this specific specialization pattern is not a problematic one (specialization over Sized is fine).

Another approach would be to simply skip that middle default impl, and require people to manually implement it for the rare occasion where they're dealing with an unsized type:

trait Sizedness {
    const IS_IT: bool;
}
impl<T> Sizedness for T {
    const FIXED_SIZE: bool = true;
}

/// etc. (this is what specialization was providing)
impl Sizedness for str {
    const FIXED_SIZE: bool = false;
}
impl<T> Sizedness for [T] {
    const FIXED_SIZE: bool = false;
}
impl Sizedness for dyn Any + '_ {
    const FIXED_SIZE: bool = false;
}

Since unsized types don't come up that often, having that generic impl for all sized types already does 90% of the job

1 Like