futursolo/stylist-rs

Unable to use Stylist 0.12.1 using trunk serve

Closed this issue · 1 comments

I am trying to use Stylist version 0.12.1 in Rust/Yew. When I build the project using Cargo build, every thing compiles without any errors.

The crate that I have n Cargo.toml looks like: stylist = { version = "0.12.1", features = ["yew"] }

However, when I use trunk serve I get the following errors:

error[E0308]: mismatched types
   --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stylist-0.12.1/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
   --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stylist-0.12.1/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
   --> /home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:571:5
    |
571 |     Some(#[stable(feature = "rust1", since = "1.0.0")] T),
    |     ^^^^

error[E0277]: `?` couldn't convert the error to `()`
   --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stylist-0.12.1/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, 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]>>
              <(T, T, T, T, T, T, T, T, T) as From<[T; 9]>>
            and 4 others
    = note: required for `Result<(), ()>` to implement `FromResidual<Result<Infallible, JsValue>>`

error[E0277]: `?` couldn't convert the error to `()`
   --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stylist-0.12.1/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, 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]>>
              <(T, T, T, T, T, T, T, T, T) as From<[T; 9]>>
            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
2023-09-12T21:39:07.427662Z ERROR ❌ error
error from HTML pipeline

The output of rustc -vV, cargo -vV and trunk -vV are:

rustc -vV
rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.71.1
LLVM version: 16.0.5

cargo -vV
cargo 1.71.1 (7f1d04c00 2023-07-29)
release: 1.71.1
commit-hash: 7f1d04c0053083b98fa50b69b6f56e339b0556a8
commit-date: 2023-07-29
host: x86_64-unknown-linux-gnu
libgit2: 1.6.4 (sys:0.17.1 vendored)
libcurl: 8.0.1-DEV (sys:0.4.61+curl-8.0.1 vendored ssl:OpenSSL/1.1.1t)
ssl: OpenSSL 1.1.1t  7 Feb 2023
os: Debian n/a (trixie) [64-bit]

trunk -vV
trunk 0.17.5

The problem can be reproduced by running the following in bash:

mkdir test
cd test

cat > Cargo.toml<<EOF
[workspace]
members = [
    "test_web"
]
EOF

cargo new test_web
cd test_web
cargo add wasm-bindgen@0.2.87
cargo add web-sys@0.3.64 -F "HtmlInputElement"
cargo add yew@0.20.0 -F csr
cargo add yew-router@0.17.0
cargo add stylist@0.12.1 -F yew
cargo install trunk --version 0.17.5
touch index.html

trunk serve  <---- this will throw errors mentioned above

The issue can also be found at: https://stackoverflow.com/questions/77092890/unable-to-use-stylist-0-12-1-using-trunk-serve

If you use a workspace, you need to enable cargo resolver 2.

See #129 for more information.