英文:
&str not converted into StyleSource implicitly in rust stylist
问题
我正在尝试在Rust中首次使用yew和stylist。根据教程,我应该能够将&str
转换为所需的类型,但它产生了以下错误:
未为`StyleSource`实现`From<&str>`特性
错误信息可参考下面的图片。
error
以下是我的代码。
use stylist::{yew::styled_component, Style};
#[styled_component(App)]
pub fn app() -> Html {
let style_str = "background-color: red;";
let stylesheet = Style::new(style_str).unwrap();
html! {
<div class={stylesheet}>
<h1>{"Hello World using stylesheet!"}</h1>
<p>{"some more text..."}</p>
</div>
}
}
我正在尝试使用在线教程进行Rust前端开发。为此,我使用了yew
和stylist
依赖项来处理HTML和CSS代码。根据文档,应该能够使用Style::new(name_of_variable)
来运行解析后的css
文件。但它抛出了上述错误。
英文:
I am trying out yew and stylist for the first time in rust. As per the tutorials, i should be able to convert &str
into the required type, but it produces the error given as:
the trait `From<&str>` is not implemented for `StyleSource`
The error is shown in the image for reference.
error
Following is my code.
use stylist::{yew::styled_component, Style};
#[styled_component(App)]
pub fn app() -> Html {
let style_str = "background-color: red;";
let stylesheet = Style::new(style_str).unwrap();
html! {
<div class={stylesheet}>
<h1>{"Hello World using stylesheet!"}</h1>
<p>{"some more text..."}</p>
</div>
}
}
I was trying frontend development in RUST using online tutorials.
To do this I was using yew
and stylist
dependencies to work with html and css codes.
As per documentation, a parsed css
file should be able to run using Style::new(name_of_variable)
. But it is throwing the stated error.
答案1
得分: 1
String conversions是通过parser
的cargo
功能实现的。您可以在Cargo.toml中启用此功能。
[dependencies]
stylist = { version = "0.12.1", features = ["parser"] }
然后,您的代码应该按原样工作。
英文:
String conversions are behind the parser
cargo feature. You can enable this feature in Cargo.toml.
[dependencies]
stylist = { version = "0.12.1", features = ["parser"] }
Then, your code should work as-is.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论