error: no matching package named `rocket_dyn_templates` found - rust

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.

Related

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.

Cargo package doesn't work with Rust's workspace?

I create a "workspace" with several folder within it following the tutorial I read here
It runs successfully with cargo run or cargo build
if all of the package were independent from each other, cargo package would run successfully. But as soon as one package depends on the other the cargo package will fail.
It displays: no matching package named "foo_2" found. location searched: registry "crates-io". Which is pretty weird, since I specifically add a local path on the dependencies.
Is this an intended behavior? if so, then why should I bother with workspace at all ?
The root Cargo.toml
[workspace]
members = [
"foo_1",
"foo_2",
]
foo_1/Cargo.toml
[package]
name = "foo_1"
version = "0.1.0"
edition = "2021"
# error here. It can't found the foo_2 package.
[dependencies]
foo_2 = { path = "../foo_2", version = "0.1.0" }
foo_2/Cargo.toml
[package]
name = "foo_2"
version = "0.1.0"
edition = "2021"
[dependencies]
Error message:
PS E:\Works\Experimentals\rust-workspace> cargo package --workspace
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
Packaging foo_1 v0.1.0 (E:\Works\Experimentals\rust-workspace\foo_1)
Verifying foo_1 v0.1.0 (E:\Works\Experimentals\rust-workspace\foo_1)
Updating crates.io index
error: failed to verify package tarball
Caused by:
no matching package named `foo_2` found
location searched: registry `crates-io`
required by package `foo_1 v0.1.0 (E:\Works\Experimentals\rust-workspace\target\package\foo_1-0.1.0)`
Packaging and publishing crates requires all dependencies of said crate to also be available in a registry. For publishing this is relatively obvious, since consumers also need to be able to fetch and build transitive dependencies. Creating tarballs also happens to have the same constraints at the moment, so it is not possible if they are not meant to be published.
Whenever you have a project with many crates in a single workspace and wish to publish them on crates.io, you would start with the crate without dependencies and work your way up to the other crates.
cargo publish -p foo_2
cargo publish -p foo_1
Or, using cargo-workspaces:
cargo workspaces publish
Is this an intended behavior?
One can still publish crates in a workspace, so long as this is done in the right order. For packaging, it is a limitation at the time of writing. The current behavior could be linked with packaging being primarily part of publishing, so this could probably be improved.
If so, then why should I bother with workspace at all?
Tangential to the matter here. Workspaces exist mainly to settle other concerns, such as having a single source of compiled dependencies with a shared dependency lock. This distinction is described in that same link.

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"

Unable to build rust's Rocket project because of framework dependency error

I'm following this tutorial here and have also looked into Rocket's official guide of setting up a web server.
I've set as default the nightly builds. But I get the following error:
error: failed to select a version for the requirement `ring = "^0.11.0"`
candidate versions found which didn't match: 0.16.11, 0.16.10, 0.16.9, ...
location searched: crates.io index
required by package `cookie v0.9.1`
... which is depended on by `rocket v0.3.6`
... which is depended on by `my-project`
Obviously there's some mismatch with the dependencies, but since ring is something required by the framework itself, I'm not sure how to debug this... furthermore, I'm using the latest versions of cargo and rust:
cargo 1.43.0-nightly (... 2020-02-18)
rustc 1.43.0-nightly (... 2020-02-21)
ring v0.11.0 was yanked from crates.io (see this issue for some background). Since some versions rocket depended on versions of ring that were yanked, those versions of rocket will no longer work.
Upgrading to rocket v0.4.0 (or the latest v0.4.2) should solve this issue.

External dependency in Rust not loading from cargo run command

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.

Resources