Questions tagged [rust-crates]

Crates are the unit of compilation in Rust.

Crates are the unit of compilation in , and the basic building block of its system.

The crates can be published in crates.io, the official Rust packages registry, where you can browse them.

206 questions
215
votes
2 answers

How to use a local unpublished crate?

I've made a library: cargo new my_lib and I want to use that library in a different program: cargo new my_program --bin extern crate my_lib; fn main { println!("Hello, World!"); } what do I need to do to get this to work? They aren't in the…
Andre S.
  • 2,372
  • 2
  • 14
  • 9
58
votes
1 answer

How do I make an Rust item public within a crate, but private outside it?

I have a crate that has lots of code, so I've split it into multiple files/modules. However, some modules have internal unsafe stuff (e.g. raw pointers) that I need to make public to the different modules, but I don't want to expose to users of my…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
48
votes
1 answer

Error installing a crate via cargo: specified package has no binaries

I'm trying to install a Rust crate on my system (Arch Linux) using Cargo. I can search for crates and find what I need, for example: $ cargo search curl | head -n3 Updating registry `https://github.com/rust-lang/crates.io-index` curl (0.3.0) …
q9f
  • 11,293
  • 8
  • 57
  • 96
47
votes
2 answers

How to clear the Cargo cache?

When I run cargo build, various libs get stored within the folder /usr/local/lib/rustlib/. What is the correct way to clear these libs? I could rm these files manually, but would that be the right thing to do? I noticed that…
bojangle
  • 888
  • 1
  • 8
  • 14
46
votes
5 answers

Rust can't find crate

I'm trying to create a module in Rust and then use it from a different file. This is my file structure: matthias@X1:~/projects/bitter-oyster$ tree . ├── Cargo.lock ├── Cargo.toml ├── Readme.md ├── src │   ├── liblib.rlib │   ├── lib.rs │   ├──…
Stein
  • 3,179
  • 5
  • 27
  • 51
35
votes
4 answers

How to tell what "features" are available per crate?

Is there a standard way to determine what features are available for a given crate? I'm trying to read Postgres timezones, and this says to use the crate postgres = "0.17.0-alpha.1" crate's with-time or with-chrono features. When I try this in my…
stuart
  • 1,785
  • 2
  • 26
  • 38
27
votes
2 answers

Should Cargo.lock be committed when the crate is both a rust library and an executable?

I 've read https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html If I understand correctly, when I commit Cargo.lock into my crate (which is both a library and an executable)'s repository, and also, publish it to crates.io, downstream…
Danielhu
  • 499
  • 4
  • 13
23
votes
3 answers

How do you read a YAML file in Rust?

I've poked the serde-yaml and yaml-rust crates a bit, but I haven't seen any examples.
semore_1267
  • 1,327
  • 2
  • 14
  • 29
18
votes
1 answer

How do I share common code between Rust projects without publishing to crates.io?

There may not be a good answer for this question, but I have code that I would like to share between two different Rust projects WITHOUT publishing the crate to crates.io. The code is proprietary and I don't want to put it out into the wild.
mattforni
  • 855
  • 5
  • 11
18
votes
3 answers

How to link against a local Rust library? (similar to npm link)

When developing a library in node, if you wish to develop against a library that only exists locally, before you npm publish, you can use npm link /path/to/other/node_library. What is the equivalent of this for Rust? How do you create another a foo…
bguiz
  • 27,371
  • 47
  • 154
  • 243
17
votes
1 answer

What exactly is a 'crate' in the Cargo ecosystem and what is the mapping to what is on crates.io?

I am a little confused as to the exact things hosted on crates.io (is a 'crate' the proper way to refer to those)? My understanding is that a crate is a unit of compilation in Rust, but then what is the mapping between crates and what is on…
nromaniv
  • 665
  • 6
  • 18
13
votes
2 answers

How can I input an integer seed for producing random numbers using the rand crate in Rust?

In a Rust project, I want to generate reproducible random numbers based on a integer seed as I'm used to in Java. The documentation for Seed in the rand crate states: Seed type, which is restricted to types mutably-dereferencable as u8 arrays (we…
Katharina
  • 243
  • 2
  • 5
12
votes
1 answer

Rust cargo.toml specify custom path for C linker and compiler

I'm having some issues due to my ignorance of cargo setup and the vast amount of documentation. The cargo.toml file is the current: [package] name = "hello" version = "0.1.0" authors = ["PC4\\Author"] [dependencies] sdl2 = { version = "0.34.1",…
CoffeDeveloper
  • 7,961
  • 3
  • 35
  • 69
11
votes
2 answers

error: failed to run custom build command for `openssl v0.9.24`

I want to install cargo-apk cargo install cargo-apk to my system (Linux Mint), but I'm getting this error error: failed to run custom build command for `openssl v0.9.24` Caused by: process didn't exit successfully:…
Jura
  • 111
  • 1
  • 4
11
votes
1 answer

How to resolve "multiple matching crates for `package`" in cargo?

When running cargo build: error: multiple matching crates for `url` It then lists the candidates: ./target/deps/liburl-11a95471847b9e04.rlib /usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liburl-4e7c5e5c.{so,rlib} ... and then aborts because…
bojangle
  • 888
  • 1
  • 8
  • 14
1
2 3
13 14