Skip to main content

downcast

Function downcast 

Source
pub fn downcast<T: Any, Target: Any>(x: T) -> Result<Target, T>
Expand description

On-stack downcasting for specialization in generic functions.

fn foo<T: Display + Any>(x: T) {
    match downcast::<T, usize>(x) {
        Ok(x) => println!("usize: {x}"),
        Err(x) => println!("other: {x}"),
    }
}