#![feature(specialization)] extern crate vectorize_struct; use vectorize_struct::vectorize_struct; use std::fmt::{Debug, Display}; #[vectorize_struct(std::fmt::Display, Debug)] struct Struct { i: i32, u: u32, b: bool, s: String, buui: (bool, u32, u8, i16), s2: String, nd: NoDisplay, } struct NoDisplay {} #[test] fn vectorize_test() { use vectorized_Struct::*; let s = Struct { i: -12, u: 61, b: false, s: String::from("asd"), buui: (true, 1, 5, -2), s2: String::from("fgh"), nd: NoDisplay {}, }; for (name, field) in s.vectorize() as Vec<(Fields, Option<&Display>)> { if let Some(field) = field { println!("{:?} can display: {}", name, field); } } for (name, field) in s.vectorize() as Vec<(Fields, Option<&Debug>)> { if let Some(field) = field { println!("{:?} can debug: {:?}", name, field); } } } #[vectorize_struct(std::fmt::Display)] struct ExampleStruct { i: i32, nd: NoDisplay, } #[test] fn doc_example() { use vectorized_ExampleStruct::{Fields, Vectorize}; let es = ExampleStruct { nd: NoDisplay {}, i: 6792, }; for (name, field) in es.vectorize() as Vec<(Fields, Option<&Display>)> { if let Some(field) = field { println!("{:?} can display: \"{}\"", name, field); } } }