7,131
questions with no upvoted or accepted answers
17
votes
0
answers
2k
views
Forwarding from a futures::Stream to a futures::Sink
I am currently trying to wrap my head around the tokio & futures primitives and ecosystem.
I started doing some work from the tk-http websockets example, and wanted to do more processing on the ...
14
votes
0
answers
708
views
Should I care about a one-definition-rule violation in a Rust executable reported by ASAN?
I have a Rust executable which was compiled purely within the Rust ecosystem; no external C code or linked libraries, sans whatever the compiler drags in.
After compiling it with ASAN on Linux, ASAN ...
13
votes
0
answers
318
views
Why is there a difference regarding lifetime elision of impl trait function arguments between async and non-async functions?
This code compiles:
async fn foo(_: impl Iterator<Item = &u32>) {}
However, removing the async, it does not work anymore:
fn foo(_: impl Iterator<Item = &u32>) {}
Instead, it ...
12
votes
1
answer
1k
views
How can I access a Rust Iterator from Python using PyO3?
I'm quite new with Rust, and my first 'serious' project has involved writing a Python wrapper for a small Rust library using PyO3. This has mostly been quite painless, but I'm struggling to work out ...
11
votes
0
answers
4k
views
rust sqlx get error "pool timed out while waiting for an open connection"
Sqlx reported an error when I used the script to loop the request
"pool timed out while waiting for an open connection"
this pool is below
Pool { size: 5, num_idle: 5, is_closed: false, ...
11
votes
0
answers
3k
views
How to run a Bevy app with default plugins without a GPU?
My laptop doesn't have a dedicated GPU. I run elementary OS 5 on this laptop, which has an integrated GPU. When I try running my beginner's Bevy app,
use bevy::prelude::*;
fn main() {
App::build()...
11
votes
0
answers
635
views
wasm_bindgen Problem with async fn in Rust
So i struggle for some time because the Rust Compiler won't give me sufficient information about this Problem.
I try to compile a Rust lib into a wasm module with wasm-pack build --out-dir [dir] but ...
11
votes
0
answers
278
views
Why does this deref coercion fail when the expression is wrapped in a block?
String implements Deref<Target = str>, which means that the following code compiles:
fn save(who: &str) {
println!("I'll save you, {}!", who);
}
save(&String::from("Madoka"));
If ...
11
votes
0
answers
160
views
How can a compiler lint pass gain access to conditional-compilation attributes like #[cfg(..)]?
Rust has a very good lint interface, divided into EarlyLintPass and LateLintPass trait objects. Unfortunately, even the early passes don't see #[cfg] or #[cfg_attr] attributes, and thus cannot lint ...
11
votes
0
answers
393
views
How can I use BLAS on Windows with the GNU toolchain?
I have this dependency:
blas = "0.18.1"
During building this simple program (no types used de facto in the program):
extern crate blas;
use blas::c::*;
I get these errors:
error: linking with `...
11
votes
0
answers
3k
views
Is it possible to use Xcode to develop applications in languages other than ObjC, C, C++, assembly and Swift?
As a concrete example, can I add a template for Rust that will allow me to develop, compile, and debug the application from inside Xcode?
My guess is that I would need to build a new Project Template ...
10
votes
0
answers
460
views
Alternative to ctor/inventory for when compiling to wasm?
The ctor crate doesn't support web assembly currently, although there is active discussion about how to fix this.
Although I am well aware of the issues associated with static initialization coming ...
10
votes
0
answers
2k
views
Is it possible to unwind on panic in `#![no_std]` mode?
Is it possible to unwind on panic in #![no_std] mode, e.g. with a customized #[panic_handler]?
10
votes
0
answers
350
views
How to make `include!` work with macros defined in external crates?
When using serde in stable as recommended by the respective blog post, one will have to use the built-in include! macro to pull in a file generated by serde-codegen.
The file linked here shows this ...
10
votes
2
answers
707
views
#[should_panic] doesn't accept constant as expected panic message
When running rust unit tests it is very useful to utilize the attribute macro #[should_panic(expect = )] to assert that the test is panicking with the correct error message (which means it's panicking ...
9
votes
0
answers
5k
views
How to fix "RPC pipe not configured" in Docker gradle attempting to clone gitlab repo
I have a Docker container for a gitlab repo that needs another gitlab repo to build. We are using Gradle scripts to do our CD/CI. I am trying to write a step in the Gradle script to clone the ...
9
votes
0
answers
2k
views
How to re-use an sqlx::Executor?
I'm trying to develop an app server in Rust using SQLX for back-end storage. It's for a primitive CMS with some idiosyncratic default behavior, to wit: if the page is not found, generate it ...
9
votes
1
answer
375
views
Error returning vector of document objects using pyo3
Returning Vector of document objects from rust to python fails.
I have a struct and method implementation in rust as follows.
use mongodb::{
bson::{Bson, Document},
error::Error,
sync::...
9
votes
0
answers
2k
views
How can I add rustdoc comments to proc macro-generated code?
I wrote a proc-macro library to accompany a library I'm writing - they go together, with the former being used to abstract away a lot of redundant code in the latter.
I am successfully generating ...
9
votes
0
answers
4k
views
How to have multiple incompatible versions of the same indirect dependency?
I'm trying to use actix-web and reqwest crates in the same project, but they depend on different versions of tokio.
Apparently, Cargo can't select a version of tokio which would satisfy all direct ...
9
votes
2
answers
2k
views
structs with boxed vs. unboxed closures
I'm still internalizing closures in Rust and how to best work with them, so this question might be somewhat vague, and there will perhaps be silly sub-questions. I'm basically looking for proper ...
9
votes
1
answer
2k
views
Possible to derive attributes *after* a struct declaration?
I'm using a macro to extend a primitive struct:
pub struct MyTypedNumber(pub u32);
struct_impl_my_features!(MyTypedNumber);
The struct_impl_my_features macro can implement functions & traits for ...
9
votes
0
answers
4k
views
How do I pretty-print Rust structures in GDB?
How do I pretty-print structures (specifically Vecs) in rust-gdb or plain gdb? Whenever I call p some_vector I get this result:
collections::vec::Vec<usize> = {buf = alloc::raw_vec::RawVec<...
8
votes
0
answers
366
views
Why is rust-mongodb library slow compared to c++ version?
I've loaded this airbnb dataset into a local mongodb(version 4.4.17) database called sample_db and collection called barcelona_cal. There are 6175334 records in the collection.
I created a small ...
8
votes
1
answer
648
views
Long build times for Criterion cargo bench but not cargo build --release with large type
While working on a Brainfuck interpreter in Rust, I noticed that cargo bench takes an incredibly long time to build a Criterion bench when the Benchmark contains a large type.
As part of my Brainfuck ...
8
votes
1
answer
533
views
Rust borrow checker and early returns
Rust-lang Playground link
struct Foo {
val: i32
}
impl Foo {
pub fn maybe_get(&mut self) -> Option<&mut i32> {
Some(&mut self.val)
}
pub fn ...
8
votes
1
answer
3k
views
Cargo build failed with = note: collect2: fatal error: cannot find 'ld'
I was trying to build my rust project on Ubuntu and got the following error:
= note: collect2: fatal error: cannot find 'ld'
compilation terminated.
error: linking with `cc` failed: exit ...
8
votes
0
answers
626
views
Why is passing DOM objects as `exnternref`s *slower* than passing through the JS value table?
I made a benchmark to measure how fast it is to call DOM APIs by passing DOM objects as exnternrefs to a Wasm function. This is the function to measure (written in Rust and compiled by rustc 1.55.0):
#...
8
votes
0
answers
2k
views
Cargo builds fails: ld framework not found Security
Trying to run a simple program and it fails with the issue
note: ld: framework not found Security
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I tried to do some ...
8
votes
0
answers
296
views
How to capture the stdout of the Python interpreter inside the Rust program when using the pyo3 crate
I am using the Rust bindings of the Python interpreter provided by the crate pyo3.
I have the following code:
fn run(script: &str) {
Python::with_gil(|py| py.run(script, None, None)).unwrap();
...
8
votes
0
answers
501
views
How can I reduce noise when tracing with Rust Warp?
When using warp with tracing enabled, I find the tracing output to be noisy. This is because a set of tracing events is emitted by every route, i.e., filter, that is attempted on each request.
So ...
8
votes
1
answer
953
views
Why can I specify a late bound lifetime parameter in one case but not the other?
Consider the following rust program:
fn f<'a>(x: &'a i32) {
unimplemented!();
}
fn main() {
f::<'static>;
}
When compiling it, the following compilation error is outputed:
...
8
votes
1
answer
253
views
Why is a lifetime required for a reference to a type in a trait bound?
I think I understood how lifetimes work with function parameters/outputs and with structs, since those cases are explained in the book (and further in the nomicon), but I do not understand how ...
8
votes
0
answers
1k
views
Using PyAny to pass Rust-created objects from Python back to Rust
I have a struct + implementation in Rust that I return to Python. This object can also be passed back to Rust for further work. (In my actual code, I'm using a HashMap<String, MyStruct>, but ...
8
votes
1
answer
3k
views
Rust OSError 22, Invalid argument when writing valid data to socket
I'm struggling to understand why I'm getting this error from a part of my program which sends ICMP echo requests on the network. The starnge thing about this is that I can get it to work by letting ...
8
votes
0
answers
1k
views
Using higher-ranked trait bounds with generics
I've stumbled upon an interesting edge case: using higher-ranked lifetime bounds to accept closures that return generic parameters, such as for<'a> FnOnce(&'a T) -> R: MyTrait. There's no ...
8
votes
0
answers
2k
views
C-style switch statement with fall-through in Rust
The match in Rust only executes one arm. I found this code snippet from Murmurhash 3:
switch(len & 15)
{
case 15: k2 ^= ((uint64_t)tail[14]) << 48;
case 14: k2 ^= ((uint64_t)tail[13]) &...
8
votes
1
answer
916
views
How can I use a Condvar with a RwLock?
I have several threads waiting on the same Condvar associated with data wrapped inside a RwLock. I'd like to call Condvar::wait and check a condition after holding the write lock to the data, but it ...
8
votes
0
answers
1k
views
What is the best way to add multiple rows using the rust-postgres crate?
I am using the rust-postgres crate to insert data into a PostgreSQL database. I scrape data from a website and want to add it to the database. I do not know ahead of time how many rows I will add in ...
8
votes
0
answers
821
views
How to disable warnings on proc-macros?
I'm using the enumflags crate, which provides the custom derive EnumFlags on enums via enumflags_derive. Additionally, I'm using Clippy with write_literal enabled.
When deriving a struct with ...
8
votes
0
answers
640
views
How do I show the standard output of my Rust program in the output window of VS Code?
I am trying to show the standard output of my Rust program in the output window of VS Code. Right now the output goes to an external command shell. Could I do it with OutputDebugString somehow? The ...
8
votes
1
answer
4k
views
What to do about warning: `extern` block uses type `u128`, which is not FFI-safe
I used the bindgen crate to create bindings from Rust to a C library but I get a whole bunch of warnings saying:
warning: `extern` block uses type `u128`, which is not FFI-safe
= note: 128-bit ...
7
votes
0
answers
125
views
Is 'static Bound on generic type mandatory
I can't figure out why I need a 'static bound in one case (bar) and not the other (baz):
fn f<T>(_input: T) -> bool {
false
}
fn bar<T>() -> Box<dyn Fn(T) -> bool + '...
7
votes
1
answer
145
views
Why does ToOwned bound Borrow instead of AsRef
If I understand correctly, Borrow and AsRef have the literally the exact same trait definitions. The difference between them is that Borrow is designed to address a specific situation with generic ...
7
votes
0
answers
110
views
Unable to generate smallest binary from Rust code
My goal is to compile Rust programs to the smallest possible binary and extract the machine code. I've made a very simple program to test.
.cargo/config
[target.x86_64-pc-windows-gnu]
rustflags = [&...
7
votes
0
answers
1k
views
Problem with reqwest as client and axum as server (axum blows up at 1k req/s with port in use error)
I have problem, why do I get this error when sending request
Error: reqwest::Error {
kind: Request,
url: Url {
scheme: "http",
cannot_be_a_base: false,
...
7
votes
0
answers
481
views
How to share a transaction between repositories?
I use sqlx to communicate with my Postgres database. I'm trying to abstract the database communication with a Repository pattern. Aslo, with this abstraction I would like to share the database ...
7
votes
0
answers
882
views
Using a Yew Callback as a wasm_bindgen Closure
This question is written for Yew v0.19
Asynchronous foreign JavaScript functions can be used in Rust through Closures, as the function to pass-in:
#[wasm_bindgen]
extern "C" {
fn ...
7
votes
1
answer
5k
views
Failed to parse manifest - Virtual manifests must be configured with [workspace]
I'm running this in powershell for my Rust project:
cargo build --target thumbv7em-none-eabihf
And it produces this error after I try to execute this command:
error: failed to parse manifest at C:\...
7
votes
0
answers
317
views
Make procedural macro compilation error point inside a token
When reporting errors in macros like println! Rust compiler shows the precise location within the format string where something has gone wrong, e.g.:
11 | println!("I'm going to substitute {...