[][src]Crate as_any

This library provides some utility traits to make working with Any smoother. This crate contains similiar functionality to the downcast crate, but simpler.

Usage example

use as_any::{AsAny, Downcast};

struct Test;

trait Custom: AsAny {
    // whatever you like to put inside of your trait
}

// implements the downcasting methods
impl as_any::Downcast for dyn Custom {}
impl as_any::Downcast for dyn Custom + Send {}
impl as_any::Downcast for dyn Custom + Sync {}
impl as_any::Downcast for dyn Custom + Send + Sync {}

impl Custom for Test {}

fn lol() {
    let x = Test;
    let y: &dyn Custom = &x;
    y.downcast_ref::<Test>().unwrap();
}

Traits

AsAny

This trait is an extension trait to Any, and adds methods to retrieve a &dyn Any

Downcast
IntoBox

A trait for the conversion of an object into a boxed trait object.

UncheckedAnyExt

This trait is an extension trait to AsAny, and adds methods for unchecked downcasts