External dependency in Rust not loading from cargo run command - rust

I am attempting to replicate code I found in a tutorial. I am using the following dependencies in my Cargo.toml file:
[dependencies]
iron = "0.5.1"
mime = "0.2.3"
router = "0.5.1"
urlencoded = "0.5.0"
I receive the following error message when I execute cargo run from the project's src directory:
Updating registry `https://github.com/rust-lang/crates.io-index`
An unknown error occurred
It hangs at "Updating registry" for roughly 15 minutes before the error appears. I would guess versioning as the issue, however the tutorial that I am using directly states that they included them as a way to avoid version mismatch with the example code.
I attempted to search for an answer but the error code is too vague to find anything.
The results of cargo run --verbose added:
Caused by:
the given version requirement is invalid
I am now getting:
failed to parse registry's information for: serde_json
and
failed to parse registry's information for: serde
when I compile/run with cargo with my listed dependencies and with "*" as the version, respectively.

Related

Is there a way to fix "maybe a missing crate [crate_name]"?

My Rust crate wont load when compiling/running my file
I have reinstalled Rust several times, continuously restarting and checking the Path variables (as well as the current version installed)
I have restarted my system various times, and I am also experiencing this issue on my desktop PC at home; I am currently running Windows 11 as of the time of this post
I have added several other "dependencies" to my Cargo.toml file to no avail, they still refuse to work and I receive the same errors each time I try to utilise it
I have seen that some features of the Rust crate importation system have been deprecated; such as the "extern crate {crate_name}", I still receive these messages from time to time even though I am using the most up to date "rustup" version
I have consulted the Rust discord server and the official Rust language forums with the same issue
I have installed "git" on my system as that appeared to be an issue when adding my desired crates to the Cargo.toml
I expected to be able to use these crates without any hassle after solving my issue on importing these crates within the toml file, but I am still with nothing to show for that expectation.
Below is the code I have fully tested and ran
I have researched the documentation for importing crates with dependencies in Rust,
my directory looks like this: file directory
I have added the "ncurses" to my MinGW package manager, as requested by the "cursive" page on "crates.io"
I also gain the error from the "rust-analyser" extension in VSC
analyser error message
I have the current version of Rust installed,
rustup -V
rustup 1.25.1 (bb60b1e89 2022-07-12)
My File Directory looks like this:
-->Application
---->src
------>main.rs
---->target
---->.gitignore
---->Cargo.lock
---->Cargo.toml
My issue occurs when I try the command "cargo build" within the VSC terminal- which to my knowledge as I am in the bin file, it should run just fine.
I am thrown this error,
c1: fatal error C1083: Cannot open source file: 'C:\Users\dean7\Desktop\main.rs\crates\cratess\target\debug\build\ncurses-
4eee2f93b40e2da2\out\chtype_size.c': Permission denied
--- stderr
cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
thread 'main' panicked at 'assertion failed: command.status().expect(\"compilation failed\").success()', C:\Users\{%USERPROFILE%}\.cargo\registry\src\github.com-1ecc6299db9ec823\ncurses-5.101.0\build.rs:105:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
My "Cargo.toml" file looks like this,
[package]
name = "cratess"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cursive = "0.20.0"
My "main.rs" file looks like this,
use cursive::{Cursive, CursiveExt};
fn main() {
let mut app = Cursive::new();
app.run();
println!("Hello, world!");
}
My error when I run the command, run my code is this,
error[E0432]: unresolved import `cursive`
--> tempCodeRunnerFile.rs:1:5
|
1 | use cursive::{Cursive, CursiveExt};
| ^^^^^^^ maybe a missing crate `cursive`?
|
= help: consider adding `extern crate cursive` to use the `cursive` crate
error: aborting due to previous error
For more information about this error, try `rustc --explain E0432`.
An additional warning is given when I run "cargo build" in my terminal (NOT IN CMD),
warning: build failed, waiting for other jobs to finish...

error: no matching package named `rocket_dyn_templates` found

I'm trying to build a small web server using Rust and the Rocket framework. For this I need the rocket_dyn_templates crate, so I did a cargo search rocket_dyn_templates, which gave as output
rocket_dyn_templates = "0.1.0-rc.2" # Dynamic templating engine integration for Rocket.
and added
rocket_dyn_templates = "0.1.0-rc2"
to the Cargo.toml file in my project.
However, when I try cargo run, cargo update or cargo package I always get the same output:
Updating crates.io index
error: no matching package named `rocket_dyn_templates` found
location searched: registry `crates-io`
required by package `calc v0.1.0 (/home/utilisateur/tmp/calc)`
I was expecting the crate to be found and downloaded, instead I keep getting the error message that no matching package was found. What am I doing wrong?
As cafce25 said, the issue was a missing . in the Cargo.toml file - it should be rc.2, not rc2.

Rust-Analyzer failed to load workspace, failing because of dependencies

[ERROR rust_analyzer::reload] failed to switch workspaces:
rust-analyzer failed to load workspace:
Failed to read Cargo metadata from Cargo.toml file
/home/supreetsingh/Documents/SavedPrograms/Rust/remind-me/Cargo.toml,
cargo 1.57.0-nightly (7fbbf4e8f 2021-10-19): Failed to run `cargo metadata --manifest-path
/home/supreetsingh/Documents/SavedPrograms/Rust/remind-me/Cargo.toml`: `cargo metadata` exited with an error: Updating crates.io index error: failed to select a version for the requirement `phf = "^0.11"`
candidate versions found which didn't match: 0.10.1, 0.10.0, 0.9.0, ... location searched: crates.io index required by package `tokio-postgres v0.7.7` ... which satisfies dependency `tokio-postgres = "^0.7.7"` (locked to 0.7.7) of package `postgres v0.19.4` ... which satisfies dependency `postgres = "^0.19.4"` (locked to 0.19.4) of package `remind-me v0.1.0 (/home/supreetsingh/Documents/SavedPrograms/Rust/remind-me)
So this problem is just arising in one rust project of mine. Cargo is in the path and this problem arose when I added one new dependency to my project and now I am stuck with this.
I have tried looking for the answer on the internet and did not find success yet, I do not know what else to try next.
cargo metadata --manifest-path <path to the file>
Works in the console I do not know why is this not working right now.
I am running this on Manjaro and my text editor is Vim with YouCompleteMe being used for AutoComplete.
If someone can point out what is wrong with the dependencies, I would be very thankful.
Thanks.
phf 0.11 requires Rust 1.60. You need to either update your Rust compiler to at least that version, or follow the chain of dependencies and downgrade the postgres crate so that you don't require phf 0.11.

is it possible to use the path when using git to add the dependencies in rust cargo

I want to add the cargo dependencies rocket-okapi as git url, now I added the dependencies like in Cargo.toml this:
rocket-okapi = { git = "https://github.com/GREsau/okapi/tree/master/rocket-okapi"}
but when I build the project using cargo build command ,shows error like this:
$ cargo build
Updating git repository `https://github.com/GREsau/okapi/tree/master/rocket-okapi`
warning: spurious network error (2 tries remaining): unexpected http status code: 404; class=Http (34)
warning: spurious network error (1 tries remaining): unexpected http status code: 404; class=Http (34)
error: failed to get `rocket-okapi` as a dependency of package `fortune v0.1.0 (/workspaces/fortune)`
Caused by:
failed to load source for dependency `rocket-okapi`
Caused by:
Unable to update https://github.com/GREsau/okapi/tree/master/rocket-okapi
Caused by:
failed to fetch into: /home/codespace/.cargo/git/db/rocket-okapi-b6c0b0836896ac76
Caused by:
network failure seems to have happened
if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
Caused by:
unexpected http status code: 404; class=Http (34)
how to add the sub folder as dependencies in rust cargo? is it possible?
There are a few things here that need a bit of clarification.
When you add a Git dependency to Cargo.toml, it expects a repository. The URL you put in there is a directory in the repository, so cargo freaks out.
Secondly, when a Git dependency is specified, cargo first looks in the repository root for a Cargo.toml file. If it cannot find any, it will search for any Cargo.toml files where the package name is the same as the dependency.
The dependency you specified, rocket-okapi, doesn't exist in the repository, so cargo gives up. Changing the name of the dependency to 'rocket_okapi' fixes this.
TL;DR: Use this
rocket_okapi = { git = "https://github.com/GREsau/okapi" }

Solana/Anchor error: (yanked dependencies) Failed to obtain package metadata: `cargo metadata` exited with an error: Updating crates.io index

I just set up a new anchor project yesterday, every command runs smoothly.
Today I installed a new anchor project. I run anchor test to see if the project is set up correctly. I am getting this error:
Failed to obtain package metadata: `cargo metadata` exited with an error: Updating crates.io index
error: failed to select a version for the requirement `anchor-lang = "^0.23.0"`
candidate versions found which didn't match: 0.24.2
location searched: crates.io index
required by package `myAnchorProject v0.1.0 (.../programs/myAnchorProject)`
It is not clear what candidate versions mean. I deleted node_modules and install it with "#project-serum/anchor": "^0.24.2", still same error.
I clear the lib.rs and testing file to see something different, but it still gives the same error.
executing cargo update is giving same error
It's not the problem with dependency in your package.json is due to the use of yanked rust crate anchor-lang
all the other version the 0.24.2 have been yanked so you can't build any cargo project which has yanked dependeny.
refer here https://crates.io/crates/anchor-lang/versions
what you need to do get it working is
go to <your-project-root>/programs/myAnchorProject/cargo.toml.
I'm assuming your program name is myAnchorProject or replace it with your program name.
your current cargo.toml must look something like
...
<other content goes here>
...
[dependencies]
anchor-lang = "^0.23.0"
you need to upgrade the anchor-lang version to 0.24.2 or any other version if available which is not yanked.
so your final cargo.toml should look like
...
<other content goes here>
...
[dependencies]
anchor-lang = "^0.24.2"

Resources