upcast 0.1.0

Simple trait for helping along upcasting of dyn supertraits. ``` pub trait A {} pub trait B: A + Upcast<dyn A> {} // Put this in your library impl<'a, T: A + 'a> UpcastFrom<T> for dyn A + 'a { fn up_from(value: &T) -> &(dyn A + 'a) { value } fn up_from_mut(value: &mut T) -> &mut (dyn A + 'a) { value } } // Now your users can do an upcast if needed, or you can within implementations fn do_cast(b: &dyn B) -> &dyn A { b.up() } ```
Documentation
  • Coverage
  • 42.86%
    3 out of 7 items documented1 out of 7 items with examples
  • Size
  • Source code size: 2.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.08 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Connicpu/upcast
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Connicpu

Simple trait for helping along upcasting of dyn supertraits.

# use upcast::{Upcast, UpcastFrom};
pub trait A {}
pub trait B: A + Upcast<dyn A> {}

// Put this in your library
impl<'a, T: A + 'a> UpcastFrom<T> for dyn A + 'a {
    fn up_from(value: &T) -> &(dyn A + 'a) { value }
    fn up_from_mut(value: &mut T) -> &mut (dyn A + 'a) { value }
}

// Now your users can do an upcast if needed, or you can within implementations
fn do_cast(b: &dyn B) -> &dyn A {
    b.up()
}