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

(* Trait *)
(* Empty module 'Flip' *)

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

Module Impl_trait_flipper_Flipper.
  Definition Self : Ty.t := Ty.path "trait_flipper::Flipper".
  
  (*
      pub fn new() -> Self {
          Self {
              value: Default::default(),
          }
      }
  *)
  Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [] =>
      ltac:(M.monadic
        (Value.StructRecord
          "trait_flipper::Flipper"
          [
            ("value",
              M.call_closure (|
                M.get_trait_method (|
                  "core::default::Default",
                  Ty.path "bool",
                  [],
                  "default",
                  []
                |),
                []
              |))
          ]))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_new : M.IsAssociatedFunction Self "new" new.
End Impl_trait_flipper_Flipper.

Module Impl_trait_flipper_Flip_for_trait_flipper_Flipper.
  Definition Self : Ty.t := Ty.path "trait_flipper::Flipper".
  
  (*
      fn flip(&mut self) {
          self.value = !self.value;
      }
  *)
  Definition flip (ε : 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_flipper::Flipper",
                "value"
              |),
              UnOp.not (|
                M.read (|
                  M.SubPointer.get_struct_record_field (|
                    M.read (| self |),
                    "trait_flipper::Flipper",
                    "value"
                  |)
                |)
              |)
            |) in
          M.alloc (| Value.Tuple [] |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  (*
      fn get(&self) -> bool {
          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_flipper::Flipper",
            "value"
          |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "trait_flipper::Flip"
      Self
      (* Trait polymorphic types *) []
      (* Instance *) [ ("flip", InstanceField.Method flip); ("get", InstanceField.Method get) ].
End Impl_trait_flipper_Flip_for_trait_flipper_Flipper.
