Skip to content

Generated httpmock Then.ok & .json_body_obj compile issues #637

@jayvdb

Description

@jayvdb

When I attempt to compile the generated output, I see

error[E0308]: mismatched types
   --> src/propolis_server_httpmock.rs:302:39
    |
302 |             Self(self.0.json_body_obj(value))
    |                         ------------- ^^^^^ expected `&_`, found `InstanceStateRequested`
    |                         |
    |                         arguments to this method are incorrect
    |
    = note: expected reference `&_`
                    found enum `propolis_server_builder::types::InstanceStateRequested`
note: method defined here
   --> /home/jayvdb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/httpmock-0.6.8/src/api/spec.rs:534:12
    |
534 |     pub fn json_body_obj<'a, T>(self, body: &T) -> Self
    |            ^^^^^^^^^^^^^
help: consider borrowing here
    |
302 |             Self(self.0.json_body_obj(&value))
    |                                       +

Some errors have detailed explanations: E0308, E0433.
For more information about an error, try `rustc --explain E0308`.

when I add & as suggested, I get errors like

error[E0277]: the trait bound `&propolis_server_builder::types::InstanceStateMonitorRequest: Deserialize<'_>` is not satisfied
   --> src/propolis_server_httpmock.rs:356:39
    |
356 |             Self(self.0.json_body_obj(&value))
    |                         ------------- ^^^^^^ the trait `Deserialize<'_>` is not implemented for `&propolis_server_builder::types::InstanceStateMonitorRequest`
    |                         |
    |                         required by a bound introduced by this call
    |
note: required by a bound in `When::json_body_obj`
   --> /home/jayvdb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/httpmock-0.6.8/src/api/spec.rs:536:24
    |
534 |     pub fn json_body_obj<'a, T>(self, body: &T) -> Self
    |            ------------- required by a bound in this associated function
535 |     where
536 |         T: Serialize + Deserialize<'a>,
    |                        ^^^^^^^^^^^^^^^ required by this bound in `When::json_body_obj`
help: consider removing the leading `&`-reference
    |
356 -             Self(self.0.json_body_obj(&value))
356 +             Self(self.0.json_body_obj(value))
    |

This is a rabbit hole, as adding #derive[serde::Deserialize, serde::Serialize] then requires Client has those traits, etc.

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