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

Module extension.
  Module permanent_delegate.
    (* StructRecord
      {
        name := "PermanentDelegate";
        ty_params := [];
        fields := [ ("delegate", Ty.path "spl_pod::optional_keys::OptionalNonZeroPubkey") ];
      } *)
    
    Module Impl_core_clone_Clone_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
      Definition Self : Ty.t :=
        Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate".
      
      (* Clone *)
      Definition clone (τ : list Ty.t) (α : list Value.t) : M :=
        match τ, α with
        | [], [ self ] =>
          ltac:(M.monadic
            (let self := M.alloc (| self |) in
            M.read (|
              M.match_operator (|
                Value.DeclaredButUndefined,
                [ fun γ => ltac:(M.monadic (M.read (| self |))) ]
              |)
            |)))
        | _, _ => M.impossible
        end.
      
      Axiom Implements :
        M.IsTraitInstance
          "core::clone::Clone"
          Self
          (* Trait polymorphic types *) []
          (* Instance *) [ ("clone", InstanceField.Method clone) ].
    End Impl_core_clone_Clone_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
    
    Module Impl_core_marker_Copy_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
      Definition Self : Ty.t :=
        Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate".
      
      Axiom Implements :
        M.IsTraitInstance
          "core::marker::Copy"
          Self
          (* Trait polymorphic types *) []
          (* Instance *) [].
    End Impl_core_marker_Copy_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
    
    Module Impl_core_fmt_Debug_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
      Definition Self : Ty.t :=
        Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate".
      
      (* Debug *)
      Definition fmt (τ : list Ty.t) (α : list Value.t) : M :=
        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_struct_field1_finish",
                []
              |),
              [
                M.read (| f |);
                M.read (| Value.String "PermanentDelegate" |);
                M.read (| Value.String "delegate" |);
                (* Unsize *)
                M.pointer_coercion
                  (M.alloc (|
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "spl_token_2022::extension::permanent_delegate::PermanentDelegate",
                      "delegate"
                    |)
                  |))
              ]
            |)))
        | _, _ => M.impossible
        end.
      
      Axiom Implements :
        M.IsTraitInstance
          "core::fmt::Debug"
          Self
          (* Trait polymorphic types *) []
          (* Instance *) [ ("fmt", InstanceField.Method fmt) ].
    End Impl_core_fmt_Debug_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
    
    Module Impl_core_default_Default_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
      Definition Self : Ty.t :=
        Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate".
      
      (* Default *)
      Definition default (τ : list Ty.t) (α : list Value.t) : M :=
        match τ, α with
        | [], [] =>
          ltac:(M.monadic
            (Value.StructRecord
              "spl_token_2022::extension::permanent_delegate::PermanentDelegate"
              [
                ("delegate",
                  M.call_closure (|
                    M.get_trait_method (|
                      "core::default::Default",
                      Ty.path "spl_pod::optional_keys::OptionalNonZeroPubkey",
                      [],
                      "default",
                      []
                    |),
                    []
                  |))
              ]))
        | _, _ => M.impossible
        end.
      
      Axiom Implements :
        M.IsTraitInstance
          "core::default::Default"
          Self
          (* Trait polymorphic types *) []
          (* Instance *) [ ("default", InstanceField.Method default) ].
    End Impl_core_default_Default_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
    
    Module Impl_core_marker_StructuralPartialEq_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
      Definition Self : Ty.t :=
        Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate".
      
      Axiom Implements :
        M.IsTraitInstance
          "core::marker::StructuralPartialEq"
          Self
          (* Trait polymorphic types *) []
          (* Instance *) [].
    End Impl_core_marker_StructuralPartialEq_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
    
    Module Impl_core_cmp_PartialEq_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
      Definition Self : Ty.t :=
        Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate".
      
      (* PartialEq *)
      Definition eq (τ : list Ty.t) (α : list Value.t) : M :=
        match τ, α with
        | [], [ self; other ] =>
          ltac:(M.monadic
            (let self := M.alloc (| self |) in
            let other := M.alloc (| other |) in
            M.call_closure (|
              M.get_trait_method (|
                "core::cmp::PartialEq",
                Ty.path "spl_pod::optional_keys::OptionalNonZeroPubkey",
                [ Ty.path "spl_pod::optional_keys::OptionalNonZeroPubkey" ],
                "eq",
                []
              |),
              [
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "spl_token_2022::extension::permanent_delegate::PermanentDelegate",
                  "delegate"
                |);
                M.SubPointer.get_struct_record_field (|
                  M.read (| other |),
                  "spl_token_2022::extension::permanent_delegate::PermanentDelegate",
                  "delegate"
                |)
              ]
            |)))
        | _, _ => M.impossible
        end.
      
      Axiom Implements :
        M.IsTraitInstance
          "core::cmp::PartialEq"
          Self
          (* Trait polymorphic types *) []
          (* Instance *) [ ("eq", InstanceField.Method eq) ].
    End Impl_core_cmp_PartialEq_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
    
    Module Impl_bytemuck_pod_Pod_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
      Definition Self : Ty.t :=
        Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate".
      
      Axiom Implements :
        M.IsTraitInstance
          "bytemuck::pod::Pod"
          Self
          (* Trait polymorphic types *) []
          (* Instance *) [].
    End Impl_bytemuck_pod_Pod_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
    
    Module Impl_bytemuck_zeroable_Zeroable_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
      Definition Self : Ty.t :=
        Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate".
      
      Axiom Implements :
        M.IsTraitInstance
          "bytemuck::zeroable::Zeroable"
          Self
          (* Trait polymorphic types *) []
          (* Instance *) [].
    End Impl_bytemuck_zeroable_Zeroable_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
    
    Module Impl_spl_token_2022_extension_Extension_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
      Definition Self : Ty.t :=
        Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate".
      
      (*     const TYPE: ExtensionType = ExtensionType::PermanentDelegate; *)
      (* Ty.path "spl_token_2022::extension::ExtensionType" *)
      Definition value_TYPE : Value.t :=
        M.run
          ltac:(M.monadic
            (M.alloc (|
              Value.StructTuple "spl_token_2022::extension::ExtensionType::PermanentDelegate" []
            |))).
      
      Axiom Implements :
        M.IsTraitInstance
          "spl_token_2022::extension::Extension"
          Self
          (* Trait polymorphic types *) []
          (* Instance *) [ ("value_TYPE", InstanceField.Constant value_TYPE) ].
    End Impl_spl_token_2022_extension_Extension_for_spl_token_2022_extension_permanent_delegate_PermanentDelegate.
    
    (*
    pub fn get_permanent_delegate<S: BaseState, BSE: BaseStateWithExtensions<S>>(
        state: &BSE,
    ) -> Option<Pubkey> {
        state
            .get_extension::<PermanentDelegate>()
            .ok()
            .and_then(|e| Option::<Pubkey>::from(e.delegate))
    }
    *)
    Definition get_permanent_delegate (τ : list Ty.t) (α : list Value.t) : M :=
      match τ, α with
      | [ _ as S; BSE ], [ state ] =>
        ltac:(M.monadic
          (let state := M.alloc (| state |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply
                (Ty.path "core::option::Option")
                [
                  Ty.apply
                    (Ty.path "&")
                    [ Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate" ]
                ],
              "and_then",
              [
                Ty.path "solana_program::pubkey::Pubkey";
                Ty.function
                  [
                    Ty.tuple
                      [
                        Ty.apply
                          (Ty.path "&")
                          [
                            Ty.path
                              "spl_token_2022::extension::permanent_delegate::PermanentDelegate"
                          ]
                      ]
                  ]
                  (Ty.apply
                    (Ty.path "core::option::Option")
                    [ Ty.path "solana_program::pubkey::Pubkey" ])
              ]
            |),
            [
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "core::result::Result")
                    [
                      Ty.apply
                        (Ty.path "&")
                        [ Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate"
                        ];
                      Ty.path "solana_program::program_error::ProgramError"
                    ],
                  "ok",
                  []
                |),
                [
                  M.call_closure (|
                    M.get_trait_method (|
                      "spl_token_2022::extension::BaseStateWithExtensions",
                      BSE,
                      [ S ],
                      "get_extension",
                      [ Ty.path "spl_token_2022::extension::permanent_delegate::PermanentDelegate" ]
                    |),
                    [ M.read (| state |) ]
                  |)
                ]
              |);
              M.closure
                (fun γ =>
                  ltac:(M.monadic
                    match γ with
                    | [ α0 ] =>
                      M.match_operator (|
                        M.alloc (| α0 |),
                        [
                          fun γ =>
                            ltac:(M.monadic
                              (let e := M.copy (| γ |) in
                              M.call_closure (|
                                M.get_trait_method (|
                                  "core::convert::From",
                                  Ty.apply
                                    (Ty.path "core::option::Option")
                                    [ Ty.path "solana_program::pubkey::Pubkey" ],
                                  [ Ty.path "spl_pod::optional_keys::OptionalNonZeroPubkey" ],
                                  "from",
                                  []
                                |),
                                [
                                  M.read (|
                                    M.SubPointer.get_struct_record_field (|
                                      M.read (| e |),
                                      "spl_token_2022::extension::permanent_delegate::PermanentDelegate",
                                      "delegate"
                                    |)
                                  |)
                                ]
                              |)))
                        ]
                      |)
                    | _ => M.impossible (||)
                    end))
            ]
          |)))
      | _, _ => M.impossible
      end.
  End permanent_delegate.
End extension.
