could not find yew in stylist - rust

I'm new to rust and yew and trying to use stylist crate with yew but when I try to import styled_components, I am getting following error.
error[E0432]: unresolved import `stylist::yew`
--> src\lib.rs:2:14
|
2 | use stylist::yew::styled_component;
| ^^^ could not find `yew` in `stylist`
For more information about this error, try `rustc --explain E0432`.
error: could not compile `hello-yew` due to previous error
2022-11-22T16:30:53.476368Z ERROR error
error from HTML pipeline
Has anyone seen this issue before?
I tried to delete previous stylist crates and tried to re-install the crate again but faced same issue.

From the docs:
Yew Integration
To enable yew integration. Enable feature yew_integration in Cargo.toml.
You can create a style and use it with yew like this:
use yew::prelude::*;
use stylist::yew::styled_component;
#[styled_component(MyStyledComponent)]
fn my_styled_component() -> Html {
html! {<div class={css!("color: red;")}>{"Hello World!"}</div>}
}

Related

Why are Bevy's Trait bounds not satisfied for the Rapier physics plugin?

I've been trying to run this minimal example to get Rapier's physics working with Bevy:
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0))
.run();
}
and it's failing:
error[E0277]: the trait bound `bevy_rapier2d::plugin::RapierPhysicsPlugin: Plugin` is not satisfied
--> src/main.rs:8:21
|
8 | .add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0))
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Plugin` is not implemented for `bevy_rapier2d::plugin::RapierPhysicsPlugin`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `Plugin`:
AnimationPlugin
AssetCountDiagnosticsPlugin<T>
AssetPlugin
AudioPlugin
BloomPlugin
CameraPlugin
CameraProjectionPlugin<T>
ColorMaterialPlugin
and 44 others
note: required by a bound in `bevy::prelude::App::add_plugin`
--> /home/techperson/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_app-0.9.0/src/app.rs:837:12
|
837 | T: Plugin,
| ^^^^^^ required by this bound in `bevy::prelude::App::add_plugin`
For more information about this error, try `rustc --explain E0277`.
Expected behavior is what is described in the Rapier documentation.
Some info:
$ cargo version
cargo 1.66.0-beta.1 (7e484fc1a 2022-10-27)
$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/techperson/.rustup
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu
beta-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
active toolchain
----------------
beta-x86_64-unknown-linux-gnu (default)
rustc 1.66.0-beta.1 (e080cc5a6 2022-11-01)
Relevant part of Cargo.toml:
[dependencies]
bevy = "0.9.0"
bevy_rapier2d = "0.18.0"
I tried manually implementing the Plugin trait, but can't because its from a different crate:
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> src/main.rs:4:1
|
4 | impl Plugin for RapierPhysicsPlugin {}
| ^^^^^^^^^^^^^^^^-------------------
| | |
| | `bevy_rapier2d::plugin::RapierPhysicsPlugin` is not defined in the current crate
| impl doesn't use only types from inside the current crate
|
= note: define and implement a trait or new type instead
For more information about this error, try `rustc --explain E0117`.
I've also tried the stable, beta, and nightly toolchains. beta and nightly fail with the aforementioned error, and stable fails because if-let statements aren't stable.
Bevy 0.9 is an extremely recent release, 3 days ago at the time of writing. It changed quite a lot about bevy internals, especially the trait system, as can be expected of an unstable project at this stage.
Most of the ecosystem will be upgrading over the course of the next few weeks. Revert back to bevy 0.8 and you should be fine for now.
I have not really tested it, only recompiled code adding the plugin and directly causing the above error. But at very least this (temporary solution) prevents that error from occurring (need to look at it bit more, but I have ran out of time for today): https://github.com/mariasiuvlad/bevy-game/pull/5/files#diff-2e9d962a08321605940b5a657135052fbcef87b5e360662bb527c96d9a615542R12
TL;DR:
bevy_rapier2d = { git = "https://github.com/devil-ira/bevy_rapier", branch = "bevy-0.9" }
EDIT: Rapier seems to have caught up with 0.9 now, so this is now inconsequential.

How do I fix material-yew use declaration?

I tried to do a hello world with material-yew.
I tried to add this use declaration according to Material Yew's home page.
use material_yew::MatButton;
I've also tried this version that I've also seen in the docs:
use material_yew::button::MatButton;
But both of them give a similar error:
error[E0432]: unresolved import material_yew::MatButton
I have these in my Cargo.toml:
[dependencies]
yew = "0.19.3"
material-yew = "0.2.0"
And I'm using trunk serve to run the app.
You need to enable the button feature (or the full feature that implies it):
material-yew = { version = "0.2.0", features = ["button"] }

How to enable unstable Rust feature str_split_once?

I'm having a hard time figuring out where do I need to write something to enable this feature.
I tried adding #![feature(str_split_once)] to the file where I'm using it but nothing happens. By Googling I found How do you enable a Rust "crate feature"? but after adding
[features]
default = ["str_split_once"]
to Cargo it doesn't build with
Caused by: feature default includes str_split_once which is
neither a dependency nor another feature
I tried adding #![feature(str_split_once)] to the file where I'm using it but nothing happens.
I guess there's not really "nothing happens", but there was a warning similar to this one:
warning: crate-level attribute should be in the root module
--> src/lib.rs:2:5
|
2 | #![feature(str_split_once)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Playground
Just add this line at the beginning of lib.rs and/or main.rs, build with nightly, and it should work:
#![feature(str_split_once)]
fn main() {
// prints Some(("test1", "test2 test3"))
println!("{:?}", "test1 test2 test3".split_once(" "));
}
Playground

Why does `cargo build` not show all errors in my code?

This code doesn't compile:
extern crate iron;
#[marco_use] //misspelled here
extern crate mime;
use iron::prelude::*;
use iron::status;
fn main() {
let mut response = Response::new();
response.set_mut(mime!(Text/Html; Charset=Utf8));
}
it shows:
error: cannot find macro `mime!` in this scope
--> src/main.rs:10:22
|
10 | response.set_mut(mime!(Text/Html; Charset=Utf8));
| ^^^^
If I add extern crate hyper; use hyper::mime::*;, then it shows:
error: The attribute `marco_use` is currently unknown to the compiler and
may have meaning added to it in the future (see issue #29642)
--> src\main.rs:2:1
|
2 | #[marco_use] extern crate mime;
| ^^^^^^^^^^^^
If I could've seen this earlier, it would've helped me to fix the mistake...
I guess Cargo only shows one error? I could not find anything about this behaviour online. How can I see all errors?
The compilation process is divided into several stages and if during one of them an error breaks the build, the following stages are not processed further. This is not specific to Cargo, but rustc as well (example: When are numeric literals assigned to default types?).
I haven't seen it officially documented, but the high-level process has been described by japaric:

Unable to build Hyper - invalid character `-` in crate name

I am trying to run the hyper example listed on the Github readme.
extern crate hyper;
use std::io::Write;
use hyper::Server;
use hyper::server::Request;
use hyper::server::Response;
use hyper::net::Fresh;
fn hello(_: Request, res: Response<Fresh>) {
let mut res = res.start().unwrap();
res.write_all(b"Hello World!").unwrap();
res.end().unwrap();
}
fn main() {
Server::http(hello).listen("127.0.0.1:3000").unwrap();
}
And the Cargo.toml looks like this:
[package]
name = <crate_name>
version = <version>
authors = <authors>
[dependencies]
hyper = "0.3"
However, when I attempt to build it using Cargo run I get the following error:
error: invalid character `-` in crate name: `build-script-build`
error: invalid character `-` in crate name: `pkg-config`
error: invalid character `-` in crate name: `rustc-serialize`
I looked through these different crates trying to see if maybe I could just change a "rustc-serialize" to "rustc_serialize" because I think that crate names can no longer have hyphens. However, I couldn't find anything of the sort. I would really like to be able to solve this problem because I have a feeling that I am going to run into this error a few more times while Rust is still being polished.
Edit: The versions are as follows:
Rust: 1.0.0-beta.2
Hyper: 0.3.14
Cargo: 0.0.1-pre-nightly (built 2015-03-09)
Your version of Hyper seems to require a newer version of Rust, which automatically converts hyphens to underscores in crate names.
See RFC 940 and Issue #23533.

Resources