Guest User

Untitled

a guest
Jan 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. use serde::Serialize;
  2.  
  3. #[derive(Serialize)]
  4. struct Struct {
  5. a: String,
  6. b: String,
  7. #[serde(skip_serializing)]
  8. c: String // marked for no serialization via serde
  9. }
  10.  
  11. #[derive(Serialize)]
  12. struct HandlebarsStruct<'a> {
  13. a: &'a String,
  14. b: &'a String,
  15. c: &'a String,
  16. }
  17.  
  18. impl Struct {
  19. fn as_handlebars_view<'a>(&'a self) -> HandlebarsStruct<'a> {
  20. HandlebarsStruct {
  21. a: &self.a,
  22. b: &self.b,
  23. c: &self.c
  24. }
  25. }
  26. }
  27.  
  28. fn main() {
  29. let s = Struct {
  30. a: "a".to_string(),
  31. b: "b".to_string(),
  32. c: "c".to_string()
  33. };
  34.  
  35. let _hb_struct = s.as_handlebars_view();
  36.  
  37. // do handlebars stuff with hb_struct
  38.  
  39. }
Add Comment
Please, Sign In to add comment