42,841 questions
0
votes
1
answer
13
views
Rust code / decorator to print / capture sourcecode as it runs
I have a main.rs file with the following repeating form
fn main() {
println!(r#"<CODE BLOCK 1>"#);
<CODE BLOCK 1>
println!(r#"<CODE BLOCK 2>"#);
...
0
votes
0
answers
16
views
Rust Polars dataframe aggregate top values from list in dataframe and join back to original dataframe
I'm trying to find a way to populate a new field in a dataframe that is the result of a group_by and aggregation.
For example, in a measurements dataframe, a column reader, has a list of animal sights ...
0
votes
0
answers
28
views
I cant get a declarative macro to work rust
I am diving into rust macros and i wanted to try something but i just cant get it to work
macro_rules! expr_enum {
(base($ch:expr)) => {
{
let expression = Enum::Base($ch);
...
-2
votes
0
answers
21
views
Checking if title can be found in SQL database and overwriting it into an CSV file [closed]
with the help of AI I wrote an Code that could read txt documents and format them into an exportable csv. Now I want the program to check if the current title can be found in the my_database.db and ...
0
votes
0
answers
23
views
Avoid Compiling protobuf-src When Building libp2p in Rust Workspace
I am working on a Rust workspace with several crates, including libp2p (version 0.54). During the build process (cargo build), I notice that protobuf-src is being compiled, which significantly ...
0
votes
0
answers
22
views
"unresolved import <my crates in project>" in Rust. Suspected to be caused by circular dependencies, but still reported an error after modification [duplicate]
I am using Rust to write a RiscV instruction set simulator, but it failed during the implementation of instruction decoding and execution. Because I encountered an issue while importing my inst and ...
-2
votes
0
answers
46
views
What is the point of `Arc::downgrade()` when `Weak` is not `Send` [closed]
You only need Arc rather than Rc if you are accessing data in different threads, but when you obtain a weak references to the Arc it is not thread-safe, so you can't store it in any data structure ...
0
votes
0
answers
82
views
How do I thread safely write a struct to memory?
I have a basic struct consisting of only atomics:
#[repr(C)]
struct Chunk {
size: AtomicU32,
flags: AtomicU32,
prev: AtomicPtr<Chunk>
}
At some point I need to create structs like ...
0
votes
0
answers
19
views
Pass `configurable-env` to cargo custom subcommand
I have a script named cargo-custom located in my $PATH. The script looks like this:
#!/usr/bin/bash
echo "Using DATA_PATH: $DATA_PATH"
echo "Cargo target dir: $CARGO_TARGET_DIR"
...
0
votes
1
answer
46
views
In rust, How to allocate a large vector to a linked list without stack overflow?
I am doing problem 234 from LeetCode. I have a function which takes as its input a linked list:
impl Solution {
pub fn is_palindrome(mut head: Option<Box<ListNode>>) -> bool {
And ...
0
votes
2
answers
46
views
How to prepare a crate for cargo publish when it needs to be built with the nightly rust toolchain?
I have extracted some functionality into a crate that I think would also be useful to others, so i would like to publish it on crates.io. However, my code makes use of some features that are not in ...
0
votes
0
answers
35
views
Replacing the backend causes changes in the behavior of the frontend
I replaced Node.js (Express) code with Rust (Actix Web) code. It caused a subtle change in the state of the frontend page. If unauthorized users access /login page, it redirects to a / page that ...
-1
votes
1
answer
43
views
Move occur because tree has type which does not implement the copy trait, value moved here
I know it's a redundant question with rust but it seems I can not manage to get some generality from it. So I attempted to write a simple binary tree using some code from elsewhere (at first I used a ...
1
vote
0
answers
43
views
glVertexAttribPointer not taking effect on first call
I'm using egui + glow in Rust. The latter should just be a wrapper layer and not be interfering, and I haven't identified any interference from the former.
I'm creating/binding a VAO, calling ...
0
votes
0
answers
33
views
Does rust ecosystem has something similar to JFR in Java? [closed]
When I have to find bottleneck in my Java application I usually use JFR for this task.
For this case I create custom event class like this
@Name(PaymentConfirmEvent.NAME)
@Label("Payment confirm ...
0
votes
0
answers
32
views
How can I get global input in bevy?
I am trying to make a music player with Bevy and Rust. I want to use global input to check if the play/pause button has been pressed even when the window is not in focus.
I've tried using a number of ...
-2
votes
0
answers
31
views
failed to compile `cargo-generate v0.22.0`, intermediate artifacts can be found at `C:\Users\13300\AppData\Local\Temp\cargo-installZmiwB5` [closed]
failed to compile cargo-generate v0.22.0, intermediate artifacts can be found at C:\Users\13300\AppData\Local\Temp\cargo-installZmiwB5.
I encountered an error while installing rust generator; what ...
0
votes
0
answers
36
views
How to handle dependent macros in Rust
I want to implement some file contents mutation functionality in Rust, but I am a bit lost on how to achieve this using procedural macros. I have an input file that is specified using an environment ...
0
votes
1
answer
36
views
how to specify conditional rustflags in cargo config file
I need to add
"-C link-arg /STACK:4000000"
but only for windows builds. I could not follow the cargo book and could not find any sample config.toml files.
-1
votes
0
answers
24
views
Resolving Rust (tonic-build)/protobuf name conflict
The Protobuf file I'm building, which is from a commercial software vendor (no changes to the server or interface possible), contains a service method called Connect:
rpc Connect (ConnectRequest) ...
0
votes
0
answers
41
views
Implement a trait for multiple generic traits
I'm trying to implement a trait for Display and Debug traits, but rust responds with conflicting implementations.
Here is my code:
pub trait AsString {
fn as_string(self) -> String;
}
impl<...
0
votes
2
answers
67
views
How can I write an efficient builder in Rust?
Lets say I want to write a type that builds a fairly large string (lets say of html) then returns it without copying or cloning the string. Is there a way that I can implement an unwrap function that ...
0
votes
2
answers
41
views
File not found for out-of-line `mod` via `include!`
My file structure looks like this (yes this is for advent of code):
days.rs
days/
day01.rs
day02.rs
...
I generate a days.in file in build.rs which looks something like this:
pub mod day01;
pub ...
0
votes
1
answer
46
views
How can I properly display data in debugging Rust in RustRover?
I'm using RustRover for some Rust programming. However debugging does work as expected.
In Settings -> Build, Execution, Deployment -> Debugger -> Data Views -> Rust there are 3 options ...
0
votes
0
answers
13
views
rust-analyzer in Visual Studio Enterprise for aarch64-pc-windows-msvc target
When opening a rust solution, Visual Studio reports "error: toolchain 'nightly--aarch64-pc-windows-msvc' does not contain component 'rust-analyzer-x86_64-pc-windows-msvc' for target 'aarch64-pc-...
0
votes
0
answers
39
views
Conceptual understanding: Specifying lifetimes for singular object owning references to its own data [duplicate]
I am still a bit newer to rust and have been getting some practice through Advent of code problems.
I am curious if anyone would be able to explain to my why the borrow checker is dislikes the ...
0
votes
0
answers
39
views
How to build a Cargo.lock file for a package within a workspace
When I cargo publish from the package directory in my workspace, I get:
error: Source directory was modified by build.rs during cargo publish. Build scripts should not modify anything outside of ...
0
votes
0
answers
43
views
How to deal with different reference & smart-pointer types [duplicate]
I'm a bit confused about how to handle the different reference and smart pointer types in this example:
use std::rc::Rc;
use std::sync::Arc;
struct Data{}
trait ApiClient {
fn load_data() -> ...
0
votes
1
answer
72
views
How to create a struct to hold all variants of an enum
I'm working on a program which uses different instructions sets depending on which option is selected, at the minute I'm using the choose_instruction_set function to choose which option is selected.
...
0
votes
1
answer
75
views
Run external command in bg (other thread), capture output when available for rendering in TUI
I'm writing a little TUI in Rust using ratatui which needs to communicate with external programms, capture the output and render it.
I know the basics of running processes in other threads and send ...
0
votes
0
answers
18
views
Rust LibP2P transaction
I’m working on a project that I plan to make open-source in the future. It’s built using Rust and LibP2P to create an environment where smartphones can connect peer-to-peer to form a decentralized ...
1
vote
1
answer
77
views
What is the different of Box<closure> and closure?
let mut x = 10;
let mut closure: Box<dyn FnMut() -> i32> = Box::new(|| {
println!("x = {}", x);
x += 5;
x
});
let value1 = closure(); // x = 10
let value2 = closure(); /...
1
vote
1
answer
16
views
Does reference not only transfer data also the type of variable
I'm really sorry for my way of questioning if it's confusing u, new to rust
let p = vec![23, 3, 31, 4];
let mut p1 = p;
p1.push(10);
let p2 = &mut p1;
p2.push(11);
The above code ownership is ...
0
votes
0
answers
27
views
Read compressed DNS message using Rust deku's crate attributes
Is it possible to read compressed DNS messages using Rust deku's crate attributes?
RFC 1035 4 Messages
RFC 1035 4.1.4. Message compression
deku attributes
If it is, how?
I've been using the until ...
1
vote
0
answers
29
views
ESP_IDF_TIME64_CHECK_LIBC: ::libc::time_t = 0 as crate::time_t; under Linux/WSL2 Ubuntu 22.04 for Esp32 [closed]
today, I have update my Rust tool chain with the last version of Rust for ESP32:
$ espup install
[info]: Installing the Espressif Rust ecosystem
[info]: Checking Rust installation
[info]: Installing ...
0
votes
0
answers
17
views
how to get data guard error to rocket catcher? [closed]
In rocket default the error catcher will return html response, I want to modify this and return json response instead:
#[catch(422)]
pub fn unprocessable_entity(req: &Request) -> Json<String&...
0
votes
0
answers
37
views
Rust debugging in VS Code Windows Aarch64 or Arm64ec
Attempting to debug rust with VS Code on a windows pc with Qualcomm Snapdragon X1 Elite X1E-78 results in error This platform (win32-arm64) is not supported. Adding the screenshot here since it's not ...
0
votes
1
answer
74
views
In Rust can I filter lines of a String that contain codes like "1.2.3" OR "1.2.3.4"?
I am building a program to help count the number of distinct codes that occur in multiple PDFs. I have got the data from the PDFs, that's not a problem. I just need to filter the lines based on ...
1
vote
0
answers
22
views
Cannot share the board between LED matrix and button in microbitV2 using rust
I am learning embedded rust by trying to recreate microbitV2 library using nrf52833_hal but got stuck.
pub struct LedMatrix {
col: [Pin<Output<PushPull>>; 5],
row: [Pin<Output&...
-1
votes
0
answers
31
views
rust clippy lint require defining magic numbres in named constant
Is there a rust clippy lint that requires defining magic numbers in named constant?
for instance:
do_something(86400);
would throw a lint error.
and
const SECONDS_IN_DAY: 86400
do_something(...
0
votes
1
answer
74
views
Access mutable cache in recursive context
I have the following code
fn foo(value: &String, cache: &mut HashMap<String, Vec<String>>) {
// values are inserted but never modified
cache.insert("a", vec![&...
1
vote
0
answers
82
views
Why can't I downcast generic wrapped in box in Rust
I have the following minimal code:
Rust Playground
use std::any::Any;
pub trait MyTrait: Any {
fn as_any(&self) -> &dyn Any;
}
impl MyTrait for Box<dyn MyTrait> {
fn as_any(...
1
vote
0
answers
40
views
How to use subquery statements in Entity::find of SeaORM?
I want to use Rust's SeaORM to implement the following SQL code: SELECT grade, ARRAY_AGG(DISTINCT student) FROM (SELECT id, grade, student FROM math_class ORDER BY id DESC LIMIT 10000) AS ...
0
votes
0
answers
36
views
Errors when trying to run and setup rustlings
While following the steps on the Rustlings website, I encountered an error: terminal output. I simply ran the provided command as instructed, without altering anything. How can I resolve this issue? I'...
1
vote
1
answer
53
views
Why does Error handling gets Result<_, _>?
I have the following function in Rust. It converts all Torrent files to Magnet links. For some files it throws an Error. I wan't to skip those files
use rs_torrent_magnet;
pub fn build_cache(paths: ...
3
votes
1
answer
39
views
Getting the UTC offset for a given chrono::DateTime
I want to write a Rust function that takes a chrono::DateTime, and returns the UTC offset of the timezone of that DateTime. This is my best attempt
fn utc_ofset<Tz: chrono::TimeZone>(dt: chrono::...
4
votes
1
answer
93
views
Is there a "High Multiplication" operation in Rust?
Throughout, I will say u16 and u32 many times. This should be understood to be a standin for uX, and u2X for any integer X (e.g. u8 and u16, u16 and u32, u32 and u64, u64 and u128).
If x, y are ...
3
votes
0
answers
48
views
How can I play multiple mp3 files without any gap in Rust?
I have some MP3 files downloaded from SoundCloud and I want to play them in sequence but whenever I've tried to do it in Rodio for example, it always had a really small gap between the audios.
use ...
0
votes
1
answer
26
views
How can I correctly pass a path that include double colons to this macro?
I'm using schemars widely in my code base, and I'm populating a rather large vector with the following (simplified) type:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CommandDescription {...
0
votes
0
answers
79
views
Integrating tch-rust with docker
Trying to run my rust app that uses tch-rs (version 0.18.0) in a docker container. Spent 30+ hours working on it and I feel like I've tried just about everything and still haven't gotten tch-rs to ...