我尝试在Rust/Yew中使用Stylist版本0.12.1。当我使用Cargo build构建项目时,所有东西都编译得没有任何错误。
我在Cargo.toml上的板条箱看起来像:stylist = { version =“0.12.1”,features = [“yew”] }
但是,当我使用trunk serve
时,我得到以下错误:
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
rustc -vV、cargo -vV和trunk -vV的输出为:
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
我的问题是我做错了什么,我如何纠正错误。
编辑在bash中运行以下命令可以重现问题:
mkdir test
cd test
cat > Cargo.toml<<EOF
[workspace]
members = [
"test_web"
]
EOF
cargo new test_web
cd test_web
cargo add [email protected]
cargo add [email protected] -F "HtmlInputElement"
cargo add [email protected] -F csr
cargo add [email protected]
cargo add [email protected] -F yew
cargo install trunk --version 0.17.5
touch index.html
trunk serve <---- this will throw errors mentioned above
1条答案
按热度按时间093gszye1#
当使用工作空间时会发生这种情况。在Cargo.toml文件中添加resolver =“2”
例如: