fn create_header_fn()

in api_generator/src/generator/code_gen/request/request_builder.rs [323:363]


    fn create_header_fn(field: &syn::Ident) -> syn::ImplItem {
        let doc_attr = doc("Adds a HTTP header");

        syn::ImplItem {
            ident: ident("header"),
            vis: syn::Visibility::Public,
            defaultness: syn::Defaultness::Final,
            attrs: vec![doc_attr],
            node: syn::ImplItemKind::Method(
                syn::MethodSig {
                    unsafety: syn::Unsafety::Normal,
                    constness: syn::Constness::NotConst,
                    abi: None,
                    decl: syn::FnDecl {
                        inputs: vec![
                            syn::FnArg::SelfValue(syn::Mutability::Mutable),
                            syn::FnArg::Captured(
                                syn::Pat::Path(None, path_none("key")),
                                syn::parse_type("HeaderName").unwrap(),
                            ),
                            syn::FnArg::Captured(
                                syn::Pat::Path(None, path_none("value")),
                                syn::parse_type("HeaderValue").unwrap(),
                            ),
                        ],
                        output: syn::FunctionRetTy::Ty(code_gen::ty("Self")),
                        variadic: false,
                    },
                    generics: generics_none(),
                },
                syn::Block {
                    stmts: vec![
                        syn::Stmt::Semi(Box::new(parse_expr(
                            quote!(self.#field.insert(key, value)),
                        ))),
                        syn::Stmt::Expr(Box::new(parse_expr(quote!(self)))),
                    ],
                },
            ),
        }
    }