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
11
votes
1 answer

How to use a macro from one crate in another?

I'm struggling to make macros from my rust lib available to other rust projects. Here's an example of how I'm trying to get this work at the moment. lib.rs: #![crate_name = "dsp"] #![feature(macro_rules, phase)] #![phase(syntax)] pub mod…
mindTree
  • 916
  • 9
  • 18
9
votes
1 answer

Unresolved import when importing from a local crate with a main.rs file

I have included a library as a submodule in my program. The structure looks like this: . ├── my_lib/ ├── Cargo.toml └── src/ ├── lib/ ├── mod.rs └── foo.rs └── main.rs ├── src/ └──…
Dani M
  • 1,173
  • 1
  • 15
  • 43
9
votes
1 answer

How can I prevent Cargo from merging the same dependency with different features?

After figuring out cargo build of the same code: spurious compile time errors?, I want to know how to prevent such a problem: $ cargo new feature_merge $ cargo add nmea $ cargo check > /dev/null 2>&1 && echo "success" success $ cargo add cexpr $…
fghj
  • 8,898
  • 4
  • 28
  • 56
8
votes
1 answer

How do I split my Rust program into many files?

I'm trying some Rust, and my program is getting somewhat long. I now want to split my program into many files -- how do I most easily do this? The Rust book chapter I get when trying to Google this has many pages about packages, crates, and modules,…
Jon Watte
  • 6,579
  • 4
  • 53
  • 63
8
votes
1 answer

Can I split crate in multiple files without introducing modules for each file?

All examples that I found create a lib.rs and then inside that file create mod foo;, mod bar; for each file foo.rs, bar.rs and so on. Basically what I want is to to split my crate into multiple files but without having to introduce lots of modules…
Christoph
  • 26,519
  • 28
  • 95
  • 133
7
votes
1 answer

Cargo.toml OS Dependency for Crate

I have a rust project where i include the mysql-crate dependency and i want to have it os independent. So i tried: Cargo.toml [package] name = "test" version = "0.1.0" authors = ["daMaex"] [dependencies] ws = "*" clap = "*" env_logger =…
7
votes
1 answer

Can't find crate for `num`

I'm trying to use BigUints from the num crate in Rust, and I'm using this code to import them: extern crate num; use num::bigint::BigUint; However, it returns the following error when I compile: main.rs:1:1: 1:18 error: can't find crate for…
Tyler
  • 486
  • 1
  • 6
  • 20
6
votes
2 answers

Rust diesel orm queries

I am new to rust and diesel orm. I am trying to execute below things on my query: count select order limit but I am getting error. I am using postgres database. I have added the exact error above the queries in comment. Here are my…
Glenn singh
  • 233
  • 1
  • 6
  • 18
6
votes
1 answer

Cross-module function call in Rust

I'm trying to call a function belonging to some module from another module (for code factoring, organization, etc). Here is my crate structure: ➜ mod_test git:(master) ✗ tree . ├── Cargo.lock ├── Cargo.toml └── src ├── bin │ └── one.rs …
Warpig
  • 73
  • 8
6
votes
2 answers

Should end user utilities/applications be registered on crates.io?

Is it acceptable to register generally useful (utilities / applications) on crates.io? The FAQ doesn't address this and from browsing, there are examples of end-user applications (mostly command line tools). Or is crates.io? meant only for…
ideasman42
  • 42,413
  • 44
  • 197
  • 320
6
votes
2 answers

Can't use a dependent crate in Rust documentation tests

I'm trying to write docs for a project I'm writing in Rust. One of the docs requires using regex::Regex. Here's the doc I'm trying to write: /// Return a list of the offsets of the tokens in `s`, as a sequence of `(start, end)` /// tuples, by…
erip
  • 16,374
  • 11
  • 66
  • 121
5
votes
2 answers

Is there a way to have a public trait in a proc-macro crate?

I have a proc-macro crate with a macro that, when expanded, needs to use custom trait implementations for Rust built-in types. I tried to define the trait in the same crate, but Rust tells me that a proc-macro crate can only have public macros (the…
jecolon
  • 188
  • 1
  • 7
5
votes
1 answer

Consistent TypeIds for dynamically loaded crates

I have a plugin system where I pass &dyn Any to a dynamically loaded rust function, but downcasting the reference fails because the TypeIds differ (for the same type), although I added rustflags = ["-Cmetadata=12345678"] to both crates' cargo…
TobiP64
  • 146
  • 3
  • 9
5
votes
1 answer

How to use "cargo yank"?

I've published my crate and then realized that I've forgotten to include some small detail in my README.md. I've included that detail into README.md and did git commit and push. How to update my crate without having to change its version? From the…
Jodimoro
  • 4,355
  • 3
  • 11
  • 18
5
votes
1 answer

Find out the current version of a crate from a lint?

I'm working on an extended deprecation lint that can decide if something already is or will be deprecated. There is one problem left, though: Crates do not appear to have version information. I know that I can get the current Crate's version using…
llogiq
  • 13,815
  • 8
  • 40
  • 72
1
2
3
13 14