Skip to content

Misleading docs on P3 resurfaced http::Response::new() #98

@itowlson

Description

@itowlson

Create the following Spin SDK P3 handler:

#[spin_sdk::http_wasip3::http_service]
async fn handle(_request: Request) -> impl IntoResponse {
    spin_sdk::http_wasip3::Response::new("done\n")
}

Rust gets mad at you:

Image

Scroll down the docs to see what you are allowed to pass to new and:

Image

It's confusing that the docs show an example of passing an &str but you're not actually allowed to. Unfortunately the Response type is a re-export so we don't control the docs.

Amusingly, you can return an &str directly...

#[spin_sdk::http_wasip3::http_service]
async fn handle(_request: Request) -> impl IntoResponse {
    "done\n"
}

...you just can't use one in a Response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions