rust-crates

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

北战南征 提交于 2021-02-16 21:20:47
问题 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 functions annotated with #[proc_macro] ) and nothing else can be public. So I put the trait in another crate and in the proc-macro crate included it as a dependency. But this means that anyone that wants to use my proc-macro crate has to depend on

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

孤街醉人 提交于 2021-02-16 21:20:08
问题 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 functions annotated with #[proc_macro] ) and nothing else can be public. So I put the trait in another crate and in the proc-macro crate included it as a dependency. But this means that anyone that wants to use my proc-macro crate has to depend on

How do I access exported functions inside a crate's “tests” directory?

南笙酒味 提交于 2021-02-07 04:18:47
问题 How do I access my libraries exported functions inside the create's "tests" directory? src/relations.rs: #![crate_type = "lib"] mod relations { pub fn foo() { println!("foo"); } } tests/test.rs: use relations::foo; #[test] fn first() { foo(); } $ cargo test Compiling relations v0.0.1 (file:///home/chris/github/relations) /home/chris/github/relations/tests/test.rs:1:5: 1:14 error: unresolved import `relations::foo`. Maybe a missing `extern crate relations`? /home/chris/github/relations/tests

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

余生颓废 提交于 2021-01-27 07:16:26
问题 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: `/tmp/cargo-install7N44TO/release/build/openssl-65bb03053b1fc095/build-script-build` (exit code: 101) --- stderr thread 'main' panicked at 'Unable to detect OpenSSL version', /home/jiri/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/build.rs:16:14 note: run with

How to add external packages and run in rust compiler?

跟風遠走 提交于 2020-08-19 16:55:25
问题 I am compiling and building an example program using rust. I chose rustc instead of cargo for compiling because it being a simple personal test project. So far using rustc for compiling and building executable worked fine but when I tried to add an external rand package its giving me this error 1 | extern crate rand; | ^^^^^^^^^^^^^^^^^^ can't find crate This is the full code extern crate rand; use rand::Rng; fn main() { for x in 1..11 { let random_number = rand::thread_rng() .gen_range(1,

How to add external packages and run in rust compiler?

你。 提交于 2020-08-19 16:52:35
问题 I am compiling and building an example program using rust. I chose rustc instead of cargo for compiling because it being a simple personal test project. So far using rustc for compiling and building executable worked fine but when I tried to add an external rand package its giving me this error 1 | extern crate rand; | ^^^^^^^^^^^^^^^^^^ can't find crate This is the full code extern crate rand; use rand::Rng; fn main() { for x in 1..11 { let random_number = rand::thread_rng() .gen_range(1,

Why does solicit 0.4.4 attempt to use openssl 0.9.12 even though I have openssl 0.7.14 in my Cargo.toml?

被刻印的时光 ゝ 提交于 2020-01-24 20:48:05
问题 I have a simple project using the Solicit example to make a request with HTTPS. My Cargo.toml has: [package] name = "test" version = "0.1.0" authors = ["einchear"] [dependencies.openssl] version = "0.7.14" features = ["tlsv1_2", "npn"] [dependencies.solicit] version = "0.4.4" features = ["tls"] When I tried to run cargo build , the error is: error: Package `openssl v0.9.12` does not have these features: `npn, tlsv1_2` Why 0.9.12 instead 0.7.14? 回答1: Solicit hasn't released a new version in

How to tell what “features” are available per crate?

空扰寡人 提交于 2020-01-23 13:03:49
问题 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 Cargo.toml: [dependencies] postgres = { version = "0.17.0-alpha.1", features = ["with-time"] } I get this error: error: failed to select a version for `postgres`. ... required by package `mypackage v0.1.0 (/Users/me/repos/mypackage)` versions that

Rust can't find crate

隐身守侯 提交于 2020-01-10 17:32:09
问题 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 │ ├── main.rs │ ├── main.rs~ │ └── plot │ ├── line.rs │ └── mod.rs └── target └── debug ├── bitter_oyster.d ├── build ├── deps ├── examples ├── libbitter_oyster.rlib └── native 8 directories, 11 files This is Cargo.toml: [package] name = "bitter-oyster" version =

Rust can't find crate

隐身守侯 提交于 2020-01-10 17:30:07
问题 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 │ ├── main.rs │ ├── main.rs~ │ └── plot │ ├── line.rs │ └── mod.rs └── target └── debug ├── bitter_oyster.d ├── build ├── deps ├── examples ├── libbitter_oyster.rlib └── native 8 directories, 11 files This is Cargo.toml: [package] name = "bitter-oyster" version =