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

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.

Related

could not find yew in stylist

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>}
}

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:

How do I build code in a documentation test but not run it?

I have code in my documentation that can only be run if the user has some software on their machine. To emulate this, I add panic! to the sample code:
//!```rust
//!fn main() {
//! panic!("Not run me");
//!}
//!```
#[cfg(test)]
mod tests {
#[test]
fn it_works() {}
}
I want to check that the code in the comments can be compiled, but I do not want it to be run during cargo test. Right now, I get:
running 1 test
test src/lib.rs - (line 1) ... FAILED
failures:
---- src/lib.rs - (line 1) stdout ----
thread 'rustc' panicked at 'test executable failed:
thread 'main' panicked at 'Not run me', <anon>:2
note: Run with `RUST_BACKTRACE=1` for a backtrace.
I read about doctest = false, but that disables not only the running of code in comments, but also syntax checking the code in comments.
How can I only disable running of code in comments, but still enable compilation of code in comments during cargo test?
There are several annotations you can use to change how the Rust code is processed. See the test documentation.
In your case it sounds like no_run is the one you'd want
//!```rust,no_run
//!fn main() {
//! panic!("Not run me");
//!}
//!```
Alternatively you could use should_panic so Rust will run the code, but expect the panic. If it's code that won't actually compile, you can use ignore.

Resources