emilk / emilk/ehttp

ehttp::Mode is not available on native targets, causing compilation errors

Open
#74 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
396
Forks
36
PR merge metrics
No merged PRs in 30d

Description

### Description
In the latest release, the `mode` field was added to `ehttp::Request` on native targets as well (likely to unify the API). However, the `ehttp::Mode` enum itself seems to still be gated behind `#[cfg(target_arch = "wasm32")]`.

As a result, it is currently impossible to construct an `ehttp::Request` manually or specify the mode on non-WASM targets, because `ehttp::Mode` cannot be imported.

### Reproduction Code
Trying to compile the following code on a native target (e.g., Linux/macOS/Windows) results in an error:
```rust
impl LoginCredentials {
fn login_request(&self, frame: &mut eframe::Frame) -> ehttp::Request {
ehttp::Request {
method: HttpMethod::Post.into(),
url: get_url(Path::Token, frame),
body: format!(
"&username={}&password={}",
self.username, self.password,
)
.into(),
headers: ehttp::Headers::new(&[
("Accept", ContentType::ApplicationJson.as_str()),
(
"Content-Type",
ContentType::ApplicationXWwwFormUrlencoded.as_str(),
),
]),
#[cfg(target_arch = "wasm32")]
mode: ehttp::Mode::default(),
timeout: None,
}
}
}
```

### Relevant Code Location
It seems the visibility of the module or the enum definition needs to be updated. I believe the issue is located here where `types` might be conditionally compiled or the `Mode` enum inside it is restricted: https://docs.rs/ehttp/latest/src/ehttp/lib.rs.html#80

### Expected Behavior
`ehttp::Mode` should be available on all targets (Native and WASM) since `ehttp::Request` now requires it regardless of the architecture.

**Environment:**
- ehttp version: 0.6.0
- Compile target: Native & WASM32

### Images

Image

Image

@emilk

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.