message: [examples/incrementer] Restructure dispatch code
diff: #![cfg_attr(not(all(test, feature = "test-env")), no_std)]
  +use parity_codec::{Decode};
  use pdsl_core::{
  env::{Env, ContractEnv},
  storage::{
  @@ -35,6 +36,16 @@ impl Incrementer {
  }
  }
  +impl Initialize for Incrementer {
  + type Args = ();
  +
  + fn initialize(&mut self, _args: Self::Args) {
  + self.current.set(0)
  + }
  +}
  +
  +// Everything below this point can be generated by the upcoming eDSL.
  +
  impl AllocateUsing for Incrementer {
  unsafe fn allocate_using<A>(alloc: &mut A) -> MaybeUninitialized<Self>
  where
  @@ -46,14 +57,6 @@ impl AllocateUsing for Incrementer {
  }
  }
  -impl Initialize for Incrementer {
  - type Args = ();
  -
  - fn initialize(&mut self, _args: Self::Args) {
  - self.current.set(0)
  - }
  -}
  -
  impl Flush for Incrementer {
  fn flush(&mut self) {
  self.current.flush()
  @@ -76,33 +79,32 @@ where
  ContractEnv::return_(&val.encode())
  }
  -#[no_mangle]
  -pub extern "C" fn deploy() {
  +fn instantiate() -> MaybeUninitialized<Incrementer> {
  unsafe {
  let mut alloc = alloc::BumpAlloc::from_raw_parts(ALLOC_KEY);
  Incrementer::allocate_using(&mut alloc)
  - .initialize(())
  - .flush()
  }
  }
  #[no_mangle]
  -pub extern "C" fn call() {
  - use parity_codec::{Decode};
  +pub extern "C" fn deploy() {
  + instantiate().initialize(()).flush()
  +}
  +#[no_mangle]
  +pub extern "C" fn call() {
  let input = ContractEnv::input();
  let action = Action::decode(&mut &input[..]).unwrap();
  - let mut incrementer = unsafe {
  - let mut alloc = alloc::BumpAlloc::from_raw_parts(ALLOC_KEY);
  - Incrementer::allocate_using(&mut alloc).unwrap()
  - };
  + let mut incrementer = instantiate().unwrap();
  match action {
  - Action::Inc(by) => {
  - incrementer.inc(by)
  - }
  Action::Get => {
  - ret(&incrementer.get())
  + let returned_val = &incrementer.get();
  + ret(&returned_val)
  + }
  + Action::Inc(by) => {
  + incrementer.inc(by);
  + incrementer.flush();
  }
  }
  }
  