Skip to content

trait-based APIs defined local to a function don't compile #1128

Open

Description

I expected this to succeed:

fn main() {
    #[dropshot::api_description]
    trait MyApi {
        type Context;
    }
    let description = my_api_mod::stub_api_description().unwrap();
    let spec = description.openapi("Counter Server", "1.0.0");
    println!(
        "{}",
        serde_json::to_string_pretty(&spec.json().unwrap()).unwrap()
    );
}

Instead it fails with:

$ cargo run --example=api-trait-broken
   Compiling dropshot v0.12.1-dev (/Users/dap/oxide/dropshot-operation-id/dropshot)
error[E0405]: cannot find trait `MyApi` in this scope
 --> dropshot/examples/api-trait-broken.rs:3:11
  |
3 |     trait MyApi {
  |           ^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0405`.
error: could not compile `dropshot` (example "api-trait-broken") due to 1 previous error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions