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

Aperta
#74 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
api

Direzione di ricerca

Inizia in ehttp/lib.rs, intorno al modulo types e alla compilazione condizionale indicata vicino alla riga 80. Compila la costruzione di Request fornita su una destinazione nativa, quindi controlla anche la destinazione WASM. È completato quando ehttp::Mode può essere importato e Request compila sia sulle destinazioni native sia sulle destinazioni WASM32.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Rust
Stelle
404
Fork
38
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di emilk/ehttp

Tutte le issue di emilk/ehttp

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.