Macro vtkio::call_numeric_fn[][src]

macro_rules! call_numeric_fn {
    ($fn:ident ::<_,$($params:ident),*>( $data:ident, $($args:expr),* ) or $err:block ) => { ... };
    ($fn:ident ::<_>( $($args:expr),* ) or $err:block ) => { ... };
    ($fn:ident ::<_,$($params:ident),*>( $data:ident ) or $err:block ) => { ... };
    ($data:ident . $fn:ident ::<_,$($params:ident),*>( $($args:expr),* ) or $err:block ) => { ... };
    ($data:ident . $fn:ident ::<_>( $($args:expr),* ) or $err:block ) => { ... };
}

Applies $fn to an IOBuffer mapping valid numeric data types by corresponding generic parameters. For example, passing an IOBuffer containing data of type u8 will cause this macro to call $fn with type parameter u8 like $fn::<u8>(io_buffer).

Examples

This example is not tested
// Implement pretty printing of `IOBuffer` contents.
impl fmt::Display for IOBuffer {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        fn display_buf<T: Any + fmt::Display>(buf: &IOBuffer, f: &mut fmt::Formatter) {
            for item in buf.iter::<T>() {
                write!(f, "{} ", item)
                    .expect("Error occurred while writing an IOBuffer.");
            }
        }
        call_numeric_fn!( display_buf::<_>(self, f) or {});
        write!(f, "")
    }
}