(* Generated by coq-of-rust *)
Require Import CoqOfRust.CoqOfRust.

(* Trait *)
(* Empty module 'Increment' *)

(* Trait *)
(* Empty module 'Reset' *)

(* StructRecord
  {
    name := "Incrementer";
    const_params := [];
    ty_params := [];
    fields := [ ("value", Ty.path "u64") ];
  } *)

Module Impl_trait_incrementer_Incrementer.
  Definition Self : Ty.t := Ty.path "trait_incrementer::Incrementer".
  
  (*
      pub fn new(init_value: u64) -> Self {
          Self { value: init_value }
      }
  *)
  Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ init_value ] =>
      ltac:(M.monadic
        (let init_value := M.alloc (| init_value |) in
        Value.StructRecord "trait_incrementer::Incrementer" [ ("value", M.read (| init_value |)) ]))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_new : M.IsAssociatedFunction Self "new" new.
  
  (*
      pub fn inc_by(&mut self, delta: u64) {
          self.value += delta;
      }
  *)
  Definition inc_by (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; delta ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let delta := M.alloc (| delta |) in
        M.read (|
          let~ _ :=
            let β :=
              M.SubPointer.get_struct_record_field (|
                M.read (| self |),
                "trait_incrementer::Incrementer",
                "value"
              |) in
            M.write (| β, BinOp.Wrap.add (| M.read (| β |), M.read (| delta |) |) |) in
          M.alloc (| Value.Tuple [] |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_inc_by : M.IsAssociatedFunction Self "inc_by" inc_by.
End Impl_trait_incrementer_Incrementer.

Module Impl_trait_incrementer_Increment_for_trait_incrementer_Incrementer.
  Definition Self : Ty.t := Ty.path "trait_incrementer::Incrementer".
  
  (*
      fn inc(&mut self) {
          self.inc_by(1)
      }
  *)
  Definition inc (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        M.call_closure (|
          M.get_associated_function (| Ty.path "trait_incrementer::Incrementer", "inc_by", [] |),
          [ M.read (| self |); Value.Integer IntegerKind.U64 1 ]
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  (*
      fn get(&self) -> u64 {
          self.value
      }
  *)
  Definition get (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        M.read (|
          M.SubPointer.get_struct_record_field (|
            M.read (| self |),
            "trait_incrementer::Incrementer",
            "value"
          |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "trait_incrementer::Increment"
      Self
      (* Trait polymorphic types *) []
      (* Instance *) [ ("inc", InstanceField.Method inc); ("get", InstanceField.Method get) ].
End Impl_trait_incrementer_Increment_for_trait_incrementer_Incrementer.

Module Impl_trait_incrementer_Reset_for_trait_incrementer_Incrementer.
  Definition Self : Ty.t := Ty.path "trait_incrementer::Incrementer".
  
  (*
      fn reset(&mut self) {
          self.value = 0;
      }
  *)
  Definition reset (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        M.read (|
          let~ _ :=
            M.write (|
              M.SubPointer.get_struct_record_field (|
                M.read (| self |),
                "trait_incrementer::Incrementer",
                "value"
              |),
              Value.Integer IntegerKind.U64 0
            |) in
          M.alloc (| Value.Tuple [] |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "trait_incrementer::Reset"
      Self
      (* Trait polymorphic types *) []
      (* Instance *) [ ("reset", InstanceField.Method reset) ].
End Impl_trait_incrementer_Reset_for_trait_incrementer_Incrementer.
