Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #![feature(specialization)]
  2.  
  3. extern crate vectorize_struct;
  4. use vectorize_struct::vectorize_struct;
  5.  
  6. use std::fmt::{Debug, Display};
  7.  
  8. #[vectorize_struct(std::fmt::Display, Debug)]
  9. struct Struct {
  10. i: i32,
  11. u: u32,
  12. b: bool,
  13. s: String,
  14. buui: (bool, u32, u8, i16),
  15. s2: String,
  16. nd: NoDisplay,
  17. }
  18.  
  19. struct NoDisplay {}
  20.  
  21. fn main() {
  22. use vectorized_Struct::*;
  23.  
  24. let s = Struct {
  25. i: -12,
  26. u: 61,
  27. b: false,
  28. s: String::from("asd"),
  29. buui: (true, 1, 5, -2),
  30. s2: String::from("fgh"),
  31. nd: NoDisplay {},
  32. };
  33.  
  34. for (name, field) in s.vectorize() as Vec<(Fields, Option<&Display>)> {
  35. if let Some(field) = field {
  36. println!("{:?} can display: {}", name, field);
  37. }
  38. }
  39.  
  40. for (name, field) in s.vectorize() as Vec<(Fields, Option<&Debug>)> {
  41. if let Some(field) = field {
  42. println!("{:?} can debug: {:?}", name, field);
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement