How to use latest couchbase-rs version from GitHub [duplicate] - rust

I want to use an EDN parser but it is inside https://github.com/mozilla/mentat. https://github.com/mozilla/mentat/tree/master/edn has its own Cargo.toml.
I tried this:
[dependencies]
edn = { git = "https://github.com/mozilla/mentat/tree/master/edn" }
But it doesn't work.
Is it possible to add dependency to this crate inside the mentat repository?

From the Cargo documentation:
Cargo will fetch the git repository at this location then look for a Cargo.toml for the requested crate anywhere inside the git repository (not necessarily at the root).
(emphasis mine)
This means that you can just say:
[dependencies]
edn = { git = "https://github.com/mozilla/mentat" }

Related

How do I specify my target chip as a feature

I would like to program a bare attiny85 with rust. No existing development board, just my own layout. I figured that attiny-hal would be what I need, but I'm stuck at this error:
$ cargo check
Checking attiny-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=4c9c44c314eb061ee20556ef10d45dea36e75ee4#4c9c44c3)
error: This crate requires you to specify your target chip as a feature.
Please select one of the following
* attiny85
* attiny88
* attiny167
* attiny2313
I tried these (and many other) settings in Crate.toml without success:
[package]
name = "avr01"
version = "0.1.0"
edition = "2021"
[features]
attiny85 = []
[dependencies.arduino-hal]
git = "https://github.com/rahix/avr-hal"
rev = "4c9c44c314eb061ee20556ef10d45dea36e75ee4"
features = ["attiny-hal"]
How do I select the target chip?
In your dependencies you have listed arduino-hal but you say you're programming a bare attiny85. You should include the attiny-hal crate directly and specify one of those features on the crate for example using this cargo command for an attiny85:
cargo add --git "https://github.com/rahix/avr-hal" attiny-hal -F attiny85
Which for some reason (I believe it's a bug) currently thinks attiny85 isn't a feature of attiny-hal but you can just specify it
in your Cargo.toml. The key for attiny-hal should include the required feature:
[dependencies.attiny-hal]
git = "https://github.com/rahix/avr-hal"
version = "*"
features = ["attiny85"]

No matching package found

I am trying to integrate an API in a yew project and facing the following issue:
Dark#Dark:/var/www/html/yew-practice$ wasm-pack build --target web
Error: Error during execution of `cargo metadata`: Updating crates.io index
Updating git repository `https://github.com/yewstack/yew`
error: no matching package found
searched package name: `yewtil`
perhaps you meant: yew
location searched: https://github.com/yewstack/yew
Cargo.toml:
[package]
name = "yew-practice"
version = "0.1.0"
edition = "2018"
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "^0.2"
serde="1"
yew = { git = "https://github.com/yewstack/yew" }
yewtil = { git = "https://github.com/yewstack/yew", features = ["fetch"] }
How do I solve the problem above?
The error tells you that no package yewtil was found in the Git repository. If you go to the repository and check its Cargo.toml file, you will indeed notice that it doesn't include a yewtil package.
I searched in the repository for yewtil, and found this pull request that refactored the project and merged yewtil into other packages: yewstack/yew#1842.
You have two options now:
Drop the dependency on yewtil, and use the documentation to figure out where the features have moved that you want to use.
Add a tag key to the dependency to pull in the latest release that included yewtil, or simply switch to the latest published version on crates.io.
If you want to get the latest features from yew, which appears to be the case given that you're pulling in the package from GitHub and not crates.io, go with option 1. You can use the documentation and the examples in the master branch to see how to use the package in its latest version.
Yew git repository is not a valid address, it must end with .git.
git = "https://github.com/yewstack/yew.git"

How can I use a library that is not on crates.io?

I want to use this library: https://github.com/stepfunc/dnp3, but it is not on crates.io, it only has a repository and I can't implement it. I tried to add it to my Cargo.toml like [dependencies] dnp3 = "0.9.1" but it says that it does not exist, and indeed it does not have a crate. Inside the repository, it has some examples in dnp3/example that have use dnp3; as if it were a crate.
How can I use this?
You can directly specify a Github (or any other git repository) as the source of the dependency.
[dependencies]
dnp3 = { git = "https://github.com/stepfunc/dnp3" }
See the Cargo reference: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories
You can specify dependencies as Git repositories.
[dependencies]
dnp3 = { git = "https://github.com/stepfunc/dnp3" }
If you want to specify a branch (assuming you do not want to use main/master), you can add a branch key to the declaration above:
[dependencies]
dnp3 = { git = "https://github.com/stepfunc/dnp3", branch = "feature/rustls" }
Related read: Specifying dependencies from git repositories
Another way to do it would be to clone the repository and use a dependency with a local path.
[dependencies]
dnp3 = { path = "../dnp3" }
Related rust docs
But of course as other answers mentioned using the git version is better in your case.

Refactoring to workspace structure causes extern crate imports to not work

I need different parts of my project to use different versions of the same extern crate so I'm refactoring my Rust project to be divided into multiple packages via the workspaces system using this as a guide. Doing so is causing all my pub extern crate imports to not work.
This post is very similar to one I created very recently and then deleted - this version contains a minimal, complete, and verifiable example.
Here's my project structure
workspace_test/
root/
src/
main.rs
Cargo.toml
Cargo.toml
workspace_test/Cargo.toml:
[package]
name = "workspace_test"
version = "0.1.0"
authors = ["Phoenix <kahlo.phoenix#gmail.com>"]
[workspace]
members = [
"root"
]
[[bin]]
name = "root"
path = "root/src/main.rs"
workspace_test/root/Cargo.toml:
[package]
name = "root"
version = "0.1.0"
authors = ["Phoenix <kahlo.phoenix#gmail.com>"]
[dependencies]
time = "0.1"
workspace_test/root/src/main.rs:
pub extern crate time;
fn main() {
println!("Hello, world!");
}
This is also on github, so it can easily be cloned and cargo run'd.
This is the error:
error[E0463]: can't find crate for `time`
--> root/src/main.rs:1:1
|
1 | pub extern crate time;
| ^^^^^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to previous error
error: Could not compile `workspace_test`.
In workspace_test/Cargo.toml you create a package with the binary root. If you execute cargo run, it runs the main.rs, but since you didn't state the dependencies in this manifest file, the error occurs. The dependency is only specified in workspace_test/root/Cargo.toml, which is not used at this point.
I assume you want to use the workspaces proposed by the RFC. You can create a workspace with virtual manifests, which must neither specify a [package] nor [[bin]], so just remove them. workspace_test/Cargo.toml now looks like this:
[workspace]
members = [
"root"
]
If you only have one executable, you can now pass the package: -p/--package
cargo run -p root
or specify the manifest path manually:
cargo run --manifest-path root/Cargo.toml
If root/Cargo.toml contains multiple targets, you can just append the --lib or --bin flags as usual. E.g. this would execute the abc-binary specified in workspace_test/root/Cargo.toml:
cargo run -p root --bin abc

How do you include all crates in a workspace inside the test directory?

I have a binary Rust project which uses the workspaces to manage sub-crates.
Directory structure
/myapp
Cargo.toml
/src
/tests
test.rs
/crates
/printer
Cargo.toml
/src
myapp/Cargo.toml
[package]
name = "myapp"
[workspace]
members = ["crates/printer"]
Inside of test.rs I can compile extern crate myapp; to pull in the parts of the application that are exposed in src/lib.rs. This works as expected.
However, when attempting to compile extern crate printer; it errors that it cannot find it. I've confirmed that the printer package is correctly placed in the top-level Cargo.lock file.
How do I include my sub-crates into the /tests directory at the top level?
There's nothing special about workspaces or even the concept of tests. If you want to use a crate in Rust code, you have to add it as a dependency:
[dependencies]
printer = { path = "crates/printer" }
See also:
How to define test-only dependencies?

Resources