#![allow(incomplete_features)] #![feature(specialization)] #![feature(unsize)] use std::marker::Unsize; pub trait Cast { fn cast(&self) -> Option<&P>; } impl Cast

for D where P: ?Sized, { default fn cast(&self) -> Option<&P> { None } } impl Cast

for D where D: Unsize

, P: ?Sized, { fn cast(&self) -> Option<&P> { Some(self) } }