Macro pcast::subtype_of [] [src]

macro_rules! subtype_of {
    ($base:ty => $sub:ty | $cerr:ty $check_fn:block) => { ... };
}

Generation conversion traits for subtype of base.

Syntax:

subtype_of!(Base => Sub | Error { ... })

The macro generates four conversion traits for Sub:

  • Deref<Target=Base> for Sub
  • TryFrom<Base, Err=Error> for Sub
  • TryFrom<&Base, Err=Error> for &Sub
  • TryFrom<&mut Base, Err=Error> for &mut Sub

All traits use the { ... } block which must expand to a Result<(), Error> to check whether or not a conversion is possible.