SHARE
TWEET

Untitled

a guest Jan 19th, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // File fenerated by Snapshot 0.0.1
  2. // DO NOT EDIT!
  3. // Number of structs: 3
  4. // StructDescriptor { ty: "Test_v3", version: 3, fields: ["field1", "field2", "is_cool"], field_types: ["u32", "String", "bool"], field_attrs: [[], [], [SnapshotFieldAttr { name: "default", value: Bool(LitBool { value: true }) }]] }
  5. impl Snapshotable for Test_v3 {
  6.     fn snapshot(&self, id: String, version: u16, snapshot: &mut Snapshot) {
  7.         match version {
  8.             3 => {
  9.                 // attributes = []
  10.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field1", 3, &self.field1);
  11.                 // attributes = []
  12.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field2", 3, &self.field2);
  13.                 // attributes = [SnapshotFieldAttr { name: "default", value: Bool(LitBool { value: true }) }]
  14.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "is_cool", 3, &self.is_cool);
  15.             }
  16.             2 => {
  17.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field1", 2, &self.field1);
  18.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field2", 2, &self.field2);
  19.             }
  20.             1 => {
  21.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field1", 1, &self.field1);
  22.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field2", 1, &self.field2);
  23.             }
  24.             _ => {}
  25.         }
  26.     }
  27.     fn restore(id: String, snapshot: &mut Snapshot) -> Self {
  28.          Test_v3 {
  29.             field1: snapshot.get_object(SnapshotPropKind::CONFIG, id.clone() + "field1").unwrap_or_default(),
  30.             field2: snapshot.get_object(SnapshotPropKind::CONFIG, id.clone() + "field2").unwrap_or_default(),
  31.             // snapshot default attr = SnapshotFieldAttr { name: "default", value: Bool(LitBool { value: true }) }
  32.             is_cool: snapshot.get_object(SnapshotPropKind::CONFIG, id.clone() + "is_cool").unwrap_or(true),
  33.         }
  34.     }
  35. }
  36. // StructDescriptor { ty: "Test_v2", version: 2, fields: ["field1", "field2"], field_types: ["u32", "String"], field_attrs: [[], []] }
  37. impl Snapshotable for Test_v2 {
  38.     fn snapshot(&self, id: String, version: u16, snapshot: &mut Snapshot) {
  39.         match version {
  40.             2 => {
  41.                 // attributes = []
  42.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field1", 2, &self.field1);
  43.                 // attributes = []
  44.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field2", 2, &self.field2);
  45.             }
  46.             1 => {
  47.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field1", 1, &self.field1);
  48.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field2", 1, &self.field2);
  49.             }
  50.             _ => {}
  51.         }
  52.     }
  53.     fn restore(id: String, snapshot: &mut Snapshot) -> Self {
  54.          Test_v2 {
  55.             field1: snapshot.get_object(SnapshotPropKind::CONFIG, id.clone() + "field1").unwrap_or_default(),
  56.             field2: snapshot.get_object(SnapshotPropKind::CONFIG, id.clone() + "field2").unwrap_or_default(),
  57.         }
  58.     }
  59. }
  60. // StructDescriptor { ty: "Test_v1", version: 1, fields: ["field1", "field2", "field3"], field_types: ["u32", "String", "Vec"], field_attrs: [[SnapshotFieldAttr { name: "default", value: Int(LitInt { token: 100 }) }], [SnapshotFieldAttr { name: "default", value: Str(LitStr { token: "default" }) }], []] }
  61. impl Snapshotable for Test_v1 {
  62.     fn snapshot(&self, id: String, version: u16, snapshot: &mut Snapshot) {
  63.         match version {
  64.             1 => {
  65.                 // attributes = [SnapshotFieldAttr { name: "default", value: Int(LitInt { token: 100 }) }]
  66.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field1", 1, &self.field1);
  67.                 // attributes = [SnapshotFieldAttr { name: "default", value: Str(LitStr { token: "default" }) }]
  68.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field2", 1, &self.field2);
  69.                 // attributes = []
  70.                 snapshot.set_object(SnapshotPropKind::CONFIG, id.clone() + "field3", 1, &self.field3);
  71.             }
  72.             _ => {}
  73.         }
  74.     }
  75.     fn restore(id: String, snapshot: &mut Snapshot) -> Self {
  76.          Test_v1 {
  77.             // snapshot default attr = SnapshotFieldAttr { name: "default", value: Int(LitInt { token: 100 }) }
  78.             field1: snapshot.get_object(SnapshotPropKind::CONFIG, id.clone() + "field1").unwrap_or(100),
  79.             // snapshot default attr = SnapshotFieldAttr { name: "default", value: Str(LitStr { token: "default" }) }
  80.             field2: snapshot.get_object(SnapshotPropKind::CONFIG, id.clone() + "field2").unwrap_or("default".to_owned()),
  81.             field3: snapshot.get_object(SnapshotPropKind::CONFIG, id.clone() + "field3").unwrap_or_default(),
  82.         }
  83.     }
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top