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

未关闭
#74 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
rust
领域
api

调研方向

从 ehttp/lib.rs 中的 types 模块附近以及第 80 行附近注明的条件编译开始。在 native target 上编译提供的 Request 构造,然后也检查 WASM target。完成的标准是可以导入 ehttp::Mode,并且 Request 能够在 native 和 WASM32 target 上编译。

由索引模型根据 Issue 内容生成。

描述

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:

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

主要语言
Rust
星标
404
派生
38
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

emilk/ehttp 的其他 Issue

查看 emilk/ehttp 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。