wrap-cli icon indicating copy to clipboard operation
wrap-cli copied to clipboard

wasm-rs: Codegen Types Should Use `str` Instead of `String`

Open dOrgJelli opened this issue 3 years ago • 0 comments

Currently the rust codegen uses String instead of str for all of its types. This is needless, since these types should be expected to be "static" and immutable.

An example of what using String looks like from a user's perspective:

let response = HttpQuery::get(&http_query::InputGet {
    url: url,
    request: Some(HttpRequest {
      response_type: HttpResponseType::TEXT,
      headers: Some(vec!(HttpHeader {
        key: String::from("user-agent"),
        value: String::from("HttpDemo")
      })),
      url_params: Some(vec!(HttpUrlParam {
        key: String::from("dummyQueryParam"),
        value: String::from("20")
      })),
      body: Some(String::from(""))
    })
});

And what it could look like if str was used:

let response = HttpQuery::get(&http_query::InputGet {
    url: url,
    request: Some(HttpRequest {
      response_type: HttpResponseType::TEXT,
      headers: Some(vec!(HttpHeader {
        key: "user-agent",
        value: "HttpDemo"
      })),
      url_params: Some(vec!(HttpUrlParam {
        key: "dummyQueryParam",
        value: "20"
      }))
    })
});

dOrgJelli avatar Jun 03 '22 02:06 dOrgJelli