[][src]Macro vtkio::call_numeric_buffer_fn

macro_rules! call_numeric_buffer_fn {
    (
$ fn : ident :: < _ , $ ( $ params : ident ) , * > (
$ data : expr , $ ( $ args : expr ) , * ) or $ err : block ) => { ... };
    (
$ fn : ident :: < _ > ( $ ( $ args : expr ) , * ) or $ err : block ) => { ... };
    (
$ fn : ident :: < _ , $ ( $ params : ident ) , * > ( $ data : expr ) 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 DataBuffer mapping valid numeric data types by corresponding generic parameters. For example, passing an DataBuffer containing data of type u8 will cause this macro to call $fn with type parameter u8 like $fn::<u8>(buffer).

Examples

// Implement pretty printing of a `DataBuffer` derivative for numeric buffers.
struct MyBuffer(DataBuffer);
impl fmt::Display for MyBuffer {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        fn display_buf<T: Any + fmt::Display>(buf: &DataBuffer, f: &mut fmt::Formatter) {
            for item in buf.iter::<T>().unwrap() {
                write!(f, "{} ", item)
                    .expect("Error occurred while writing MyBuffer.");
            }
        }
        call_numeric_buffer_fn!( display_buf::<_>(&self.0, f) or {});
        write!(f, "")
    }
}