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

Module iter.
  Module adapters.
    Module by_ref_sized.
      (* StructTuple
        {
          name := "ByRefSized";
          const_params := [];
          ty_params := [ "I" ];
          fields := [ Ty.apply (Ty.path "&mut") [] [ I ] ];
        } *)
      
      Module Impl_core_fmt_Debug_where_core_fmt_Debug_I_for_core_iter_adapters_by_ref_sized_ByRefSized_I.
        Definition Self (I : Ty.t) : Ty.t :=
          Ty.apply (Ty.path "core::iter::adapters::by_ref_sized::ByRefSized") [] [ I ].
        
        (* Debug *)
        Definition fmt (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [], [ self; f ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let f := M.alloc (| f |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.path "core::fmt::Formatter",
                  "debug_tuple_field1_finish",
                  []
                |),
                [
                  M.read (| f |);
                  M.read (| Value.String "ByRefSized" |);
                  M.alloc (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom Implements :
          forall (I : Ty.t),
          M.IsTraitInstance
            "core::fmt::Debug"
            (Self I)
            (* Trait polymorphic types *) []
            (* Instance *) [ ("fmt", InstanceField.Method (fmt I)) ].
      End Impl_core_fmt_Debug_where_core_fmt_Debug_I_for_core_iter_adapters_by_ref_sized_ByRefSized_I.
      
      Module Impl_core_iter_traits_iterator_Iterator_where_core_iter_traits_iterator_Iterator_I_for_core_iter_adapters_by_ref_sized_ByRefSized_I.
        Definition Self (I : Ty.t) : Ty.t :=
          Ty.apply (Ty.path "core::iter::adapters::by_ref_sized::ByRefSized") [] [ I ].
        
        (*     type Item = I::Item; *)
        Definition _Item (I : Ty.t) : Ty.t := Ty.associated.
        
        (*
            fn next(&mut self) -> Option<Self::Item> {
                I::next(self.0)
            }
        *)
        Definition next (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::iterator::Iterator",
                  I,
                  [],
                  "next",
                  []
                |),
                [
                  M.read (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        (*
            fn size_hint(&self) -> (usize, Option<usize>) {
                I::size_hint(self.0)
            }
        *)
        Definition size_hint (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::iterator::Iterator",
                  I,
                  [],
                  "size_hint",
                  []
                |),
                [
                  M.read (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        (*
            fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
                I::advance_by(self.0, n)
            }
        *)
        Definition advance_by
            (I : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [], [ self; n ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let n := M.alloc (| n |) in
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::iterator::Iterator",
                  I,
                  [],
                  "advance_by",
                  []
                |),
                [
                  M.read (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |);
                  M.read (| n |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        (*
            fn nth(&mut self, n: usize) -> Option<Self::Item> {
                I::nth(self.0, n)
            }
        *)
        Definition nth (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [], [ self; n ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let n := M.alloc (| n |) in
              M.call_closure (|
                M.get_trait_method (| "core::iter::traits::iterator::Iterator", I, [], "nth", [] |),
                [
                  M.read (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |);
                  M.read (| n |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        (*
            fn fold<B, F>(self, init: B, f: F) -> B
            where
                F: FnMut(B, Self::Item) -> B,
            {
                // `fold` needs ownership, so this can't forward directly.
                I::try_fold(self.0, init, NeverShortCircuit::wrap_mut_2(f)).0
            }
        *)
        Definition fold (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [ B; F ], [ self; init; f ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let init := M.alloc (| init |) in
              let f := M.alloc (| f |) in
              M.read (|
                M.SubPointer.get_struct_tuple_field (|
                  M.alloc (|
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::iter::traits::iterator::Iterator",
                        I,
                        [],
                        "try_fold",
                        [
                          B;
                          Ty.associated;
                          Ty.apply (Ty.path "core::ops::try_trait::NeverShortCircuit") [] [ B ]
                        ]
                      |),
                      [
                        M.read (|
                          M.SubPointer.get_struct_tuple_field (|
                            self,
                            "core::iter::adapters::by_ref_sized::ByRefSized",
                            0
                          |)
                        |);
                        M.read (| init |);
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "core::ops::try_trait::NeverShortCircuit") [] [ B ],
                            "wrap_mut_2",
                            [ B; Ty.associated; F ]
                          |),
                          [ M.read (| f |) ]
                        |)
                      ]
                    |)
                  |),
                  "core::ops::try_trait::NeverShortCircuit",
                  0
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        (*
            fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
            where
                F: FnMut(B, Self::Item) -> R,
                R: Try<Output = B>,
            {
                I::try_fold(self.0, init, f)
            }
        *)
        Definition try_fold (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [ B; F; R ], [ self; init; f ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let init := M.alloc (| init |) in
              let f := M.alloc (| f |) in
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::iterator::Iterator",
                  I,
                  [],
                  "try_fold",
                  [ B; F; R ]
                |),
                [
                  M.read (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |);
                  M.read (| init |);
                  M.read (| f |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom Implements :
          forall (I : Ty.t),
          M.IsTraitInstance
            "core::iter::traits::iterator::Iterator"
            (Self I)
            (* Trait polymorphic types *) []
            (* Instance *)
            [
              ("Item", InstanceField.Ty (_Item I));
              ("next", InstanceField.Method (next I));
              ("size_hint", InstanceField.Method (size_hint I));
              ("advance_by", InstanceField.Method (advance_by I));
              ("nth", InstanceField.Method (nth I));
              ("fold", InstanceField.Method (fold I));
              ("try_fold", InstanceField.Method (try_fold I))
            ].
      End Impl_core_iter_traits_iterator_Iterator_where_core_iter_traits_iterator_Iterator_I_for_core_iter_adapters_by_ref_sized_ByRefSized_I.
      
      Module Impl_core_iter_traits_double_ended_DoubleEndedIterator_where_core_iter_traits_double_ended_DoubleEndedIterator_I_for_core_iter_adapters_by_ref_sized_ByRefSized_I.
        Definition Self (I : Ty.t) : Ty.t :=
          Ty.apply (Ty.path "core::iter::adapters::by_ref_sized::ByRefSized") [] [ I ].
        
        (*
            fn next_back(&mut self) -> Option<Self::Item> {
                I::next_back(self.0)
            }
        *)
        Definition next_back (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::double_ended::DoubleEndedIterator",
                  I,
                  [],
                  "next_back",
                  []
                |),
                [
                  M.read (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        (*
            fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
                I::advance_back_by(self.0, n)
            }
        *)
        Definition advance_back_by
            (I : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [], [ self; n ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let n := M.alloc (| n |) in
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::double_ended::DoubleEndedIterator",
                  I,
                  [],
                  "advance_back_by",
                  []
                |),
                [
                  M.read (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |);
                  M.read (| n |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        (*
            fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
                I::nth_back(self.0, n)
            }
        *)
        Definition nth_back (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [], [ self; n ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let n := M.alloc (| n |) in
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::double_ended::DoubleEndedIterator",
                  I,
                  [],
                  "nth_back",
                  []
                |),
                [
                  M.read (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |);
                  M.read (| n |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        (*
            fn rfold<B, F>(self, init: B, f: F) -> B
            where
                F: FnMut(B, Self::Item) -> B,
            {
                // `rfold` needs ownership, so this can't forward directly.
                I::try_rfold(self.0, init, NeverShortCircuit::wrap_mut_2(f)).0
            }
        *)
        Definition rfold (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [ B; F ], [ self; init; f ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let init := M.alloc (| init |) in
              let f := M.alloc (| f |) in
              M.read (|
                M.SubPointer.get_struct_tuple_field (|
                  M.alloc (|
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::iter::traits::double_ended::DoubleEndedIterator",
                        I,
                        [],
                        "try_rfold",
                        [
                          B;
                          Ty.associated;
                          Ty.apply (Ty.path "core::ops::try_trait::NeverShortCircuit") [] [ B ]
                        ]
                      |),
                      [
                        M.read (|
                          M.SubPointer.get_struct_tuple_field (|
                            self,
                            "core::iter::adapters::by_ref_sized::ByRefSized",
                            0
                          |)
                        |);
                        M.read (| init |);
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "core::ops::try_trait::NeverShortCircuit") [] [ B ],
                            "wrap_mut_2",
                            [ B; Ty.associated; F ]
                          |),
                          [ M.read (| f |) ]
                        |)
                      ]
                    |)
                  |),
                  "core::ops::try_trait::NeverShortCircuit",
                  0
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        (*
            fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
            where
                F: FnMut(B, Self::Item) -> R,
                R: Try<Output = B>,
            {
                I::try_rfold(self.0, init, f)
            }
        *)
        Definition try_rfold (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self I in
          match ε, τ, α with
          | [], [ B; F; R ], [ self; init; f ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let init := M.alloc (| init |) in
              let f := M.alloc (| f |) in
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::double_ended::DoubleEndedIterator",
                  I,
                  [],
                  "try_rfold",
                  [ B; F; R ]
                |),
                [
                  M.read (|
                    M.SubPointer.get_struct_tuple_field (|
                      M.read (| self |),
                      "core::iter::adapters::by_ref_sized::ByRefSized",
                      0
                    |)
                  |);
                  M.read (| init |);
                  M.read (| f |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom Implements :
          forall (I : Ty.t),
          M.IsTraitInstance
            "core::iter::traits::double_ended::DoubleEndedIterator"
            (Self I)
            (* Trait polymorphic types *) []
            (* Instance *)
            [
              ("next_back", InstanceField.Method (next_back I));
              ("advance_back_by", InstanceField.Method (advance_back_by I));
              ("nth_back", InstanceField.Method (nth_back I));
              ("rfold", InstanceField.Method (rfold I));
              ("try_rfold", InstanceField.Method (try_rfold I))
            ].
      End Impl_core_iter_traits_double_ended_DoubleEndedIterator_where_core_iter_traits_double_ended_DoubleEndedIterator_I_for_core_iter_adapters_by_ref_sized_ByRefSized_I.
    End by_ref_sized.
  End adapters.
End iter.
