Why are multiple imports from the Hyper crate failing? - rust

I'm working on a very simple HTTP client in Rust, built on top of the hyper (GitHub, crates.io) crate.
When I try to replicate the examples/client.rs file in a new Cargo project using cargo build (as well as using rustc src/main.rs), I get multiple errors caused by failed imports from hyper.
Here's the top of my main.rs:
extern crate hyper;
use hyper::client::{Client, Request, Response, DefaultTransport as HttpStream};
use hyper::header::Connection;
use hyper::{Decoder, Encoder, Next};
The rest of the file is, except for some comments, identical to the examples/client.rs file from the hyper repository.
At compile time, I get the following errors:
src/main.rs:10:48: 10:78 error: unresolved import `hyper::client::DefaultTransport`. There is no `DefaultTransport` in `hyper::client` [E0432]
src/main.rs:10 use hyper::client::{Client, Request, Response, DefaultTransport as HttpStream};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:10:48: 10:78 help: run `rustc --explain E0432` to see a detailed explanation
src/main.rs:12:13: 12:20 error: unresolved import `hyper::Decoder`. There is no `Decoder` in `hyper` [E0432]
src/main.rs:12 use hyper::{Decoder, Encoder, Next};
^~~~~~~
src/main.rs:12:13: 12:20 help: run `rustc --explain E0432` to see a detailed explanation
src/main.rs:12:22: 12:29 error: unresolved import `hyper::Encoder`. There is no `Encoder` in `hyper` [E0432]
src/main.rs:12 use hyper::{Decoder, Encoder, Next};
^~~~~~~
src/main.rs:12:22: 12:29 help: run `rustc --explain E0432` to see a detailed explanation
src/main.rs:12:31: 12:35 error: unresolved import `hyper::Next`. There is no `Next` in `hyper` [E0432]
src/main.rs:12 use hyper::{Decoder, Encoder, Next};
^~~~
src/main.rs:12:31: 12:35 help: run `rustc --explain E0432` to see a detailed explanation
src/main.rs:53:6: 53:40 error: trait `hyper::client::Handler` is not in scope [E0405]
src/main.rs:53 impl hyper::client::Handler<HttpStream> for Dump {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:53:6: 53:40 help: run `rustc --explain E0405` to see a detailed explanation
src/main.rs:53:6: 53:40 help: you can to import it into scope: `use hyper::server::Handler;`.
In case it may contribute to this issue, here are the contents of my Cargo.toml:
name = "my_project"
version = "0.0.1"
authors = ["email#example.com"]
[dependencies]
getopts = "0.2"
hyper = "0.9.6"
[[bin]]
name = "my_project"
Some of the imports are actually working, so assuming the example in the repository is up to date, I really can't tell what's wrong. The source files of the crate look like they expose the involved types, but I'm very new to Rust so I may be misreading the files.

You are using examples from the master branch that do not work with 0.9.6 version. You can take a look at examples on the branch 0.9.6 or make cargo use hyper direct from github, writing on Cargo.toml:
[dependencies]
hyper = {git = "https://github.com/hyperium/hyper"}

Related

Kitties tutorial part 1 build is failing with unresolved import for sc_client_api RemoteBackend, anyone faced this issue?

I just followed the tutorial, I am at the first
cargo build --release
This is the error I am getting, any idea why this would happen?
error[E0432]: unresolved import `sc_client_api::RemoteBackend`
--> node/src/service.rs:4:39
|
4 | use sc_client_api::{ExecutorProvider, RemoteBackend};
| ^^^^^^^^^^^^^
| |
| no `RemoteBackend` in the root
| help: a similar name exists in the module: `StateBackend`
I solved this by removing RemoteBackend from the import at node/src/service.rs.
Just change the line (for me it was Line 4) at node/src/service.rs from
use sc_client_api::{ExecutorProvider, RemoteBackend};
to
use sc_client_api::ExecutorProvider;
While working with the tutorial cargo build --release resulted in the following error message:
error[E0432]: unresolved import `sc_client_api::RemoteBackend`
--> node/src/service.rs:4:39
|
4 | use sc_client_api::{ExecutorProvider, RemoteBackend};
| ^^^^^^^^^^^^^
| |
| no `RemoteBackend` in the root
| help: a similar name exists in the module: `StateBackend`
The help message provided some clue as to what was happening. Checking the node/src/service.rs file, I found that RemoteBackend was never referenced anywhere else in the file. So I simply removed it from the imports, and the build process was completed successfully.

unresolved import `crate::sys` on rust project building

I am working on the Solana contract with rust language.
When I execute cargo build, it returns ok result.
But when I execute cargo +bpf build --target bpfel-unknown-unknown --release, it returns below the error console.
error[E0432]: unresolved import `crate::sys`
--> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.2/src/sockaddr.rs:5:12
|
5 | use crate::sys::{
| ^^^
| |
| unresolved import
| help: a similar path exists: `crate::socket::io::sys`
error[E0432]: unresolved imports `crate::sys`, `crate::sys`
--> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.2/src/socket.rs:21:12
|
21 | use crate::sys::{self, c_int, getsockopt, setsockopt, Bool};
| ^^^ ^^^^ no `sys` in the root
| |
| unresolved import
| help: a similar path exists: `crate::socket::io::sys`
...
Please let me know if you faced this kinda issue before.
On-chain programs are limited in what resources they can access. For example, you can't access the internet or filesystem. Your program seems to be relying on some of these forbidden packages.
Here's more info from the documentation about using rand, which is also not allowed: https://docs.solana.com/developing/on-chain-programs/developing-rust#depending-on-rand

How can I use the crate : “bech32-no_std” in rust?

In Cargo.toml, I add the code:
[dependencies]
bech32-no_std = "0.7.3"
When I want to use it:
use bech32-no_std::{u5, CheckBase32};
This raised an error:
Syntax Error: expected BANGrust-analyzer
Syntax Error: expected `{`, `[`, `(`rust-analyzer
Syntax Error: expected SEMICOLONrust-analyzer
unresolved macro `self::no_std!`rust-analyzerunresolved-macro-call
This may be caused by no_std. It should be just a grammatical problem, but i don't know how to solve it.

Use of static_assert forbidden in Android project

I am porting some C++ code to Android. One of the source files includes a webrtc header file that causes error during compilation. I have reduced the problem to this simple code:
template <class T, int n>
struct DefaultDeleter<T[n]> {
// Never allow someone to declare something like scoped_ptr<int[10]>.
static_assert(sizeof(T) == -1, "do not use array with size as type");
};
The error I get is:
[armeabi-v7a] Compile++ thumb: dummyclient <= dummy.cpp
dummy.cpp:7:3: warning: identifier 'static_assert' will become a keyword in C++0x [-Wc++0x-compat]
dummy.cpp:5:8: error: 'DefaultDeleter' is not a template
dummy.cpp:7:17: error: expected identifier before 'sizeof'
dummy.cpp:7:17: error: expected ',' or '...' before 'sizeof'
dummy.cpp:7:70: error: ISO C++ forbids declaration of 'static_assert' with no type [-fpermissive]
The same code compiles fine on Windows and Linux. Is there some compiler settings that are required for Android? Regards.
You need to pass the CPPFLAG -std=c++11.

when I include atomic.h, GCC says No such file, why?

I want to use atomic API, and I include . I don't know how to use it! Thank you!
I have it in /usr/src/linux-headers-2.6.28-11/arch/x86/include/asm/atomic.h.
I also add -I/usr/src/linux-headers-2.6.28-11/arch/x86/include/ and -I/usr/src/linux-headers-2.6.28-11/include.
Some other errors is produced because of -DCONFIG_X86_32 and -D__KERNEL__ macro undefined.
Then I define the two macros,
some errors occurred:
/usr/src/linux-headers-2.6.28-11/include/linux/cpumask.h:600:37: error: "and" may not appear in macro parameter list
/usr/src/linux-headers-2.6.28-11/arch/x86/include/asm/processor.h:159:1: warning: "cache_line_size" redefined
/usr/src/linux-headers-2.6.28-11/include/linux/cache.h:64:1: warning: this is the location of the previous definition
/usr/src/linux-headers-2.6.28-11/include/linux/stddef.h:16: error: expected identifier before ‘false’
/usr/src/linux-headers-2.6.28-11/include/linux/stddef.h:16: error: expected `}' before ‘false’
/usr/src/linux-headers-2.6.28-11/include/linux/stddef.h:16: error: expected unqualified-id before ‘false’
/usr/src/linux-headers-2.6.28-11/include/linux/stddef.h:18: error: expected declaration before ‘}’ token
My system is ubuntu 9.04 running on Virtualbox3.0.
If you know where the file is on your HD, then you say gcc mySource.c -I/path/to/atomic
note that this assumes you include "atomic" directly. and not "some/path/atmomic.h"

Resources