Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-export HeaderName #180

Closed
wants to merge 1 commit into from
Closed

Conversation

andrewtoth
Copy link
Contributor

@andrewtoth andrewtoth commented Nov 1, 2023

After #179 we need to re-export HeaderName so &str can be converted to HeaderName for Mock::match_header and Mock::with_header.

For example, the following won't compile because header.as_str() doesn't live for 'static:

        let header: String = "content-type".to_string();
        let mut server = mockito::Server::new();

        server.mock("GET", "/greetings").match_header(
            header.as_str(),
            "application/json",
        );

The following won't compile because the compiler can't infer what type we're trying into:

        let header: String = "content-type".to_string();
        let mut server = mockito::Server::new();

        server.mock("GET", "/greetings").match_header(
            header.as_str().try_into().unwrap(),
            "application/json",
        );

We need to explicitly convert to a HeaderName, and we can't do that unless we have the type re-exported:

        let header: String = "content-type".to_string();
        let mut server = mockito::Server::new();

        server.mock("GET", "/greetings").match_header(
            mockito::HeaderName::try_from(header).unwrap(),
            "application/json",
        );

@lipanski
Copy link
Owner

lipanski commented Nov 1, 2023

Closing this in favour of #181

I prefer that one because I'd like to avoid exposing types from other crates if possible. It also keeps things a bit more backwards compatible.

@lipanski lipanski closed this Nov 1, 2023
@andrewtoth andrewtoth deleted the headername branch November 1, 2023 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants