futursolo / stylist-rs

A CSS-in-Rust styling solution for WebAssembly Applications
https://crates.io/crates/stylist
MIT License
366 stars 22 forks source link

Bug?, Error?: | expected `()`, found `JsValue` | and | the trait `From<JsValue>` is not implemented for `()` | #156

Closed Garkatron closed 4 months ago

Garkatron commented 4 months ago

Explanation, details:

I'm trying to create a simple web-page app using examples while I review the documentation. However, I encounter an error displayed on the terminal when I attempt to execute it with trunk serve --open.

Sorry if, in the end, the issue isn't actually a problem and it turns out my code is incorrect. My fault.

My code:

Cargo.toml

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
yew = { version = "0.21", features = ["csr"] }
stylist = { version = "0.13.0", features = ["yew", "parser"] }

App.rs

use yew::prelude::*;

#[function_component(App)]
pub fn app() -> Html {
    let a: Style = style!(r#"background-color: red;"#).unwrap();
    html! {
        <main>
            <div class={a}>
                {"da"}
            </div>
        </main>
    }
}

Main.rs

mod app;

use app::App;

fn main() {
    yew::Renderer::<App>::new().render();
}

[Rustc version] rustc 1.76.0 (07dca489a 2024-02-04)

[Cargo version] cargo 1.76.0 (c84b36747 2024-01-18)

[Trunk version] trunk 0.18.8

The docs I read: link = https://docs.rs/stylist/latest/stylist/


This is the entire message from the terminal.

PS D:\Carpetas\Proyectos\EmailClient\web-app> trunk serve --open 2024-02-24T20:22:06.611349Z INFO Starting trunk 0.18.8 2024-02-24T20:22:06.613302Z INFO starting build 2024-02-24T20:22:06.615707Z INFO spawning asset pipelines 2024-02-24T20:22:06.818957Z INFO building trunk-template warning: virtual workspace defaulting to resolver = "1" despite one or more workspace members being on edition 2021 which implies resolver = "2" note: to keep the current resolver, specify workspace.resolver = "1" in the workspace root's manifest note: to use the edition 2021 resolver, specify workspace.resolver = "2" in the workspace root's manifest note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions Compiling stylist v0.13.0 error[E0308]: mismatched types --> C:\Users\user.cargo\registry\src\index.crates.io-6f17d22bba15001f\stylist-0.13.0\src\manager\mod.rs:244:38 244 .map_err( e Error::Web(Some(e))) ---- ^ expected (), found JsValue
arguments to this enum variant are incorrect
help: the type constructed contains JsValue due to the type of the argument passed --> C:\Users\user.cargo\registry\src\index.crates.io-6f17d22bba15001f\stylist-0.13.0\src\manager\mod.rs:244:33 244 .map_err( e Error::Web(Some(e))) ^^^^^-^
this argument influences the type of Some

note: tuple variant defined here --> C:\Users\user.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library/core/src/option.rs:578:5 | 578 | Some(#[stable(feature = "rust1", since = "1.0.0")] T), | ^^^^

error[E0277]: ? couldn't convert the error to () --> C:\Users\user.cargo\registry\src\index.crates.io-6f17d22bba15001f\stylist-0.13.0\src\manager\mod.rs:255:91 255 if let Some(m) = document.query_selector(&format!("style[data-style={}]", id))? { ^ the trait From<JsValue> is not implemented for ()
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the following other types implement trait `From<T>`:
          <(T,) as From<[T; 1]>>
          <(T, T) as From<[T; 2]>>
          <(T, T, T) as From<[T; 3]>>
          <(T, T, T, T) as From<[T; 4]>>
          <(T, T, T, T, T) as From<[T; 5]>>
          <(T, T, T, T, T, T) as From<[T; 6]>>
          <(T, T, T, T, T, T, T) as From<[T; 7]>>
          <(T, T, T, T, T, T, T, T) as From<[T; 8]>>
        and 4 others
= note: required for `Result<(), ()>` to implement `FromResidual<Result<Infallible, JsValue>>`
error[E0277]: ? couldn't convert the error to () --> C:\Users\user.cargo\registry\src\index.crates.io-6f17d22bba15001f\stylist-0.13.0\src\manager\mod.rs:257:44 257 parent.remove_child(&m)?; ^ the trait From<JsValue> is not implemented for ()
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the following other types implement trait `From<T>`:
          <(T,) as From<[T; 1]>>
          <(T, T) as From<[T; 2]>>
          <(T, T, T) as From<[T; 3]>>
          <(T, T, T, T) as From<[T; 4]>>
          <(T, T, T, T, T) as From<[T; 5]>>
          <(T, T, T, T, T, T) as From<[T; 6]>>
          <(T, T, T, T, T, T, T) as From<[T; 7]>>
          <(T, T, T, T, T, T, T, T) as From<[T; 8]>>
        and 4 others
= note: required for `Result<(), ()>` to implement `FromResidual<Result<Infallible, JsValue>>`

Some errors have detailed explanations: E0277, E0308. For more information about an error, try rustc --explain E0277. error: could not compile stylist (lib) due to 3 previous errors 2024-02-24T20:22:07.228717Z ERROR error error from build pipeline

Caused by: 0: HTML build pipeline failed (1 errors), showing first 1: error from asset pipeline 2: error during cargo build execution 3: cargo call to executable 'cargo' with args: '["build", "--target=wasm32-unknown-unknown", "--manifest-path", "D:\Carpetas\Proyectos\EmailClient\web-app\Cargo.toml"]' returned a bad status: exit code: 101 2024-02-24T20:22:07.236936Z INFO serving static assets at -> / 2024-02-24T20:22:07.237214Z INFO server listening at http://127.0.0.1:8080

WorldSEnder commented 4 months ago

This is caused by an internal workaround for a compiler bug (hard to explain inline here). Duplicate of #129. Simply set resolver = "2" in your workspace's Cargo.toml as the compiler warning tells you to anyway.

Feel free to reopen if that doesn't fix it.