Questions tagged [rust]

Rust is a systems programming language without a garbage collector focused on three goals: safety, speed, and concurrency. Use this tag for questions about code written in Rust. Use an edition specific tag for questions that refer to code which requires a particular edition, like [rust-2018]. Use more specific tags for subtopics like [rust-cargo] and [rust-macros].

Filter by
Sorted by
Tagged with
0 votes
0 answers
16 views

How to return structs, Result, Option from Rust in WASM?

This question is based on this discussion. I need to return different structures, Option, Result. I noticed the externalref crate, but it is in experimental status and I can't use it. I was trying to ...
Yurii Stolbetskyi's user avatar
0 votes
0 answers
13 views

rust jni environment test setup on mac

I am using crate jni = { version = "0.20.0", features = ["invocation"] } and was trying to setup a test that could run JNI stuff. my boot code is as follows let jvm_args = ...
zinking's user avatar
  • 5,571
0 votes
0 answers
24 views

Using the parser combinator crate "nom" to partially read and parse a file

I have a usecase where I only want to parse the beginning of a file to to the point where I decide to stop parsing. This can be 4kB or more. The exact amount is not known. So there is no need to read ...
Frank Schwidom's user avatar
0 votes
0 answers
20 views

How to replace the response in the webview2 using rust

I write a program with tauri. I want to intercept the request and replace the response content. But i can't get the response, when the program execute 'args.Response().unwrap', it throw some errors: ...
Tom Chen's user avatar
0 votes
0 answers
20 views

Reconstructing files coming on UDP with Rust pcap lib

I am writing a small web service in Rust that listens to the UDP traffic, and writes the content into local files. For that I use the Rust pcap library. I manage to listen to the stream and write to a ...
matt's user avatar
  • 1,056
5 votes
1 answer
56 views

prevent a trait function from being implemented by other struct

I just build a trait Bar with 2 functions (alpha() with implementation and beta() with only interfaces), and I hope the struct who implement Bar implements only beta(), and never implement their own ...
Rahn's user avatar
  • 4,915
0 votes
0 answers
36 views

How can I implement a rust constructor compiled to wasm that will allow for javascript destructuring? [duplicate]

I'm using rust-wasm, wasm-bindgen, to create a javascript wrapper for a rust library. I have a rust constructor currently defined like #[wasm_bindgen(js_class = Dater)] impl DaterWrapper { #[...
daidoji70's user avatar
  • 328
1 vote
1 answer
53 views

Can I split an iterator with Item=(key, val) into separate key iter and val iter without collecting or cloning?

I have a function that looks like this: fn set_many(&mut self, key_vals: impl IntoIterator<Item = (Index, T)>) { let (keys, vals): (Vec<_>, Vec<_>) = key_vals....
danda's user avatar
  • 583
-1 votes
0 answers
64 views

How should I implement a rust constructor compiled to wasm that will allow for javascript destructuring? [closed]

I'm using rust-wasm, wasm-bindgen, to create a javascript wrapper for a rust library. I have a rust constructor currently defined like #[wasm_bindgen(js_class = Dater)] impl DaterWrapper { #[...
daidoji70's user avatar
  • 328
0 votes
1 answer
48 views

Writable and ReadOnly data block for generic processing pipeline in Rust

I'm am new to Rust and am trying to build a generic block-based processing pipeline. I want the blocks to be distinguished into ReadableBlock and WritableBlock but I want the underlying datatypes to ...
Cole's user avatar
  • 53
0 votes
0 answers
72 views

Unwrapping Option fields using &self in methods [duplicate]

My type has one field which is an Option. I am writing a method that accesses the field via the object reference. However, I cannot unwrap the Option field because that would be moving stuff that is ...
yujaiyu's user avatar
  • 8,762
-2 votes
0 answers
45 views

Rust Diesel on MAC M2 [closed]

I use Diesel with Rust and on macOS during migration, I have the following error: diesel migration run diesel(49302,0x1dfdcd300) malloc: \*\*\* error for object 0xba: pointer being freed was not ...
Piotr B's user avatar
0 votes
0 answers
26 views

Mismatched type on generic function type with type alias

I'm build a simple API and trying to implement clean architecture in Rust, I am using a trait to implement some sort of interface to abstract database implementation. In my in memory database ...
Vitor Lacerda's user avatar
0 votes
0 answers
31 views

Generate PKCS#10 CSR from RSA Private & Public Keys. How?

I am new to Rust and have finally found something to learn from that keeps me interested throughout the steep learning curve; encryption. I was wondering if Rust is mature enough to produce the same ...
suchislife's user avatar
-1 votes
0 answers
26 views

Turning a terminal game into a web app with Rust [closed]

the last months I have been working on implementing connect four with some players (e.g. MonteCarlo, Min-Max ...) in rust. Now I would like to be able to host the game on a site like fly.io with a ...
Raoul Luqué's user avatar
0 votes
0 answers
64 views

Rust: Any beautiful way to read types from CLI args?

This is my code: https://github.com/jesusvico/tfm-marlin/blob/master/src/main.rs use structopt::StructOpt; mod printers; mod dummy_circuit; mod circuit_traits; use printers::*; use ark_relations::...
Prankster2k's user avatar
0 votes
0 answers
16 views

Diesel Rust Query: 'the trait bound not satisfied' error when mapping query result to struct

the trait bound (diesel::sql_types::Integer, Text, Text, diesel::sql_types::Timestamp, diesel::sql_types::Timestamp, Text): load_dsl::private::CompatibleType<User, Mysql> is not satisfied use ...
Yu Yang's user avatar
0 votes
0 answers
34 views

How to store a tree of traits in rust?

I have the next code: use std::{ fmt::Debug, rc::Rc, cell::RefCell, }; pub trait ILifeCycle { fn on_start(&mut self); fn on_update(&mut self); fn on_stop(&mut ...
Denis Steinman's user avatar
0 votes
0 answers
17 views

Rust Based Websocket Server blocks after n connections

first of all i'm fairly new to Rust. I'm implementing a WebSocket Server which maybe someday will run in our Kubernetes cluster (yes i'm aware of the statefull issue with websockets in such an ...
Thomas Spycher's user avatar
0 votes
1 answer
37 views

pass struct and its member field(s) as mutable references to a function

How to avoid passing mutable reference of a struct and mutable reference of its field(s) to a function. I know I'm violating the the rule "only one mutable reference or any number of immutable ...
Harry's user avatar
  • 2,269
0 votes
0 answers
28 views

Cargo run doesn't read json input

I'm new in rust and i have some problems.I have a project written in rust, I need to run a debug. My configuration is(rustrover): But when I run or debug, an error appears: Error reading args.json: ...
Minas's user avatar
  • 11
-2 votes
0 answers
33 views

How to update rustc in Docker [closed]

I tried to implement a fuzzing tool RULF for Rust, but encountered an error in the fifth step. Using cargo install afl prompted the following error: Then I used cargo install cargo-afl, but the ...
TanjiaJunS's user avatar
2 votes
1 answer
54 views

How to move struct variable with Mutex data in Rust?

I'm trying to translate a C++ program that uses a Bank object, with methods that change an account's balance and uses mutexes so this can happen in parallel. In this program, each account had a lock I ...
Naginipython's user avatar
2 votes
0 answers
44 views

Why my example segfaults on movaps instruction?

Here https://github.com/vivekvpandya/vivek is my completed code. I am trying run a program with no_std on bare matel x86. Can someone please explain why following code fails? #[cfg(not(feature = "...
llvm_ninja's user avatar
0 votes
1 answer
53 views

How do I define a type for a variable which gets filled by an 'impl' return type of a function?

I refer to the example given in 'rustc --explain E0562'. I want an assignment to a variable explicitly typed. How can I do that? { // rustc --explain E0562 fn count_to_n(n: usize) -> impl ...
Frank Schwidom's user avatar
0 votes
0 answers
37 views

Turning npm package into an .exe file - what am I doing wrong?

I want to include the npm package Mapshaper as a dependency in my Tauri/Svelte app. I'm using it to reduce the file size of some .shp files after I download them from an API. However, it does not do ...
Sidders's user avatar
  • 125
2 votes
1 answer
60 views

Which files should I be putting in my GitHub Repository

I'm making a GitHub repository for my rust project but there are a lot of files, so I was just wondering: Which files should I be putting in the repository and which ones should I absolutely make sure ...
Kazuala's user avatar
  • 25
0 votes
1 answer
34 views

Rust Specs Crate Generic Component in System

I am trying to implement a system to use a generic component, but I keep having issues with join method when I try to mutate the variable. Here is a simplified version of the code I have: use specs::{...
Sergio Cavaleiro Costa's user avatar
3 votes
4 answers
82 views

How to deserialize a map into a vector of a custom struct, with a field matching the key?

Given a yaml with a map of items, items: item1: uid: ab1234 foo: bar item2: uid: cd5678 foo: baz how can I parse it with serde into a Vec<Item> with a new field, "name&...
Sparkler's user avatar
  • 2,643
1 vote
1 answer
49 views

Rust, my module introduction suddenly encountered a problem

This is a problem that has never occurred before, and it suddenly appeared after I added the Excel function use crate::common::offic::excel; // <<-- use clap::Parser; use jni::objects::*; use ...
menghan_xiaoshuo's user avatar
1 vote
1 answer
57 views

Can I modify an &'a str on a struct instance in rust so that it has the same &'a str lifetime after modification?

struct test<'a> { name: &'a str } impl<'a> test<'a> { fn modify_name(&'a mut self) { let new_name = self.name.replacen("az", "", 1); ...
Boldizsár Németh's user avatar
5 votes
0 answers
57 views

Why does trait implementation only conflict within same crate?

and furthermore, it depends on the details of the trait. I have two minimal crates. The first is a library crate foo, containing #![allow(incomplete_features)] #![feature(generic_const_exprs)] pub ...
ajp's user avatar
  • 1,927
0 votes
2 answers
51 views

Is it safe to make RefCell Sync+Send if the data it contains is protected by RwLock?

I'm trying to make a thread-safe data type, with locking full encapsulated so that callers never see or directly hold a lock. (This part works fine.) Further, there is a requirement that the struct ...
danda's user avatar
  • 583
1 vote
0 answers
61 views

Is it safe to synchronize access to non-Sync data using only a separate atomic variable?

Suppose I write my own mutex class, containing data of some arbitrary type T and an AtomicBool with which I intend to synchronize access to the data: struct MyMutex<T> { in_use: AtomicBool, ...
alter_igel's user avatar
  • 6,936
2 votes
2 answers
51 views

Structs of booleans as a 1-byte bitmask

If you have the following struct of booleans, Rust Analyzer says it takes up 3 bytes because there's three fields. struct Mask { field_1: bool, field_2: bool, field_3: bool, } // size = 3, ...
Nick's user avatar
  • 5,514
0 votes
1 answer
36 views

Rust trait with multiple members, implemented by default, that depend on each other

Suppose I want to introduce a trait with 2 methods, that are dependent on each other in the sense, that one of them can be implemented by default using another. For example: use std::io; trait ...
Serhii Ch's user avatar
4 votes
2 answers
78 views

how to borrow mutable reference to different fields of a struct using RefCell::borrowmut

How do I get mutable references to different fields of a struct stored inside a RefCell. What is the harm in getting mutable references to different fields of a struct? use std::cell::{RefCell, RefMut}...
Harry's user avatar
  • 2,269
0 votes
0 answers
42 views

global immutable HashMap in Rust [duplicate]

How to create a global immutable HashMap in Rust? use std::collections::HashMap; pub const ID_INDEX_MAPPER: HashMap<u16, u16> = [ (13287, 0), (2387, 1), (5873, 2), ].iter().cloned()....
Harry's user avatar
  • 2,269
-1 votes
0 answers
44 views

How can I treat multi clients same IP address and same port number?

Environment: macOS Sonoma Ver.14.0 (M1 mac) Rust Ver.1.65.0 I am running the following function in multiple threads. The way I expect this code to work is for multiple clients with the same IP ...
matsuisa's user avatar
0 votes
0 answers
45 views

How to allow for plugins as separate crates

I have a rust crate (that is published on crates.io). The functionality that crate provides is also available as a command line utility, that can be installed using cargo install. This command line ...
ChrisB's user avatar
  • 2,024
0 votes
1 answer
37 views

How do you define a static method collection in a generic struct

I am trying to use a collection of static method as generics inside a struct in order to change the behavior of a part of my code simply by changing the implementation of my trait. My issue is that I ...
recouer's user avatar
  • 45
0 votes
1 answer
54 views

Why is D3D12GetDebugInterface failing with "no such interface supported" using Rust's windows-rs crate?

I'm getting the following error when getting a D3D12DebugInterface in Rust using the windows-rs crate: failed to get d3d12 debug interface: No such interface supported (0x80004002) Here's the code ...
junglie85's user avatar
  • 1,295
2 votes
2 answers
90 views

Trait bound i8: From<u8> was not satisfied

For the sake of the argument, let's say I want to learn how to build a simple generic structure representing a 2D vector. pub struct Vector<T> { x: T, y: T, } Now, obviously, I want to make ...
aHzuPFd's user avatar
  • 33
2 votes
1 answer
107 views

Is it possible to have a generic Rust T be always heap allocated?

use std::ops::Deref; struct Test { last: &'static str, list: Vec<String>, } // This is safe because we own the value and will not modify it. // When dropping, `last` will be ...
Yuri Astrakhan's user avatar
0 votes
0 answers
33 views

Dumping LLVMModule with Value Names using the C-API

I am currently writing my own compiler using Rust and LLVM and therefore, the LLVM-C-API. For Debugging purposes, the LLVM-C-API provides a Function called LLVMDumpModule(). Sadly, this seems to ...
Jonas's user avatar
  • 73
0 votes
0 answers
65 views

How to decode the token of a Basic Auth request

I have this code: #[get("/devices")] async fn devices(req: HttpRequest) -> Result<impl Responder, Error> { let devices_data = vec![ Device { id_device: 123, speed: 65.4,...
joegsuero's user avatar
0 votes
0 answers
79 views

How to implement a map on the top of a btree?

Assumption: I know there is a BTreeMap in the std. Lets say we have some Btree structure: BTree<T: Ord + Eq> And we want to implement a map using it: struct Node<K: Ord + Eq, V> { k: K, ...
user3070377's user avatar
-1 votes
0 answers
26 views

Can't debug rust in VSCode due-to @rpath/libc++.1.dylib

When trying to debug rust in VSCode, there is an error: dyld[24992]: Library not loaded: @rpath/libc++.1.dylib Referenced from: <E5F2890B-A104-3EA1-BD19-3C85826B6D5A> <long_path>/target/...
gavrilikhin.d's user avatar
-2 votes
0 answers
42 views

How to implement hooks in Rust when performing insert, update, delete operations in SQLite? [closed]

I want this to happen: When I perform Insert, Update, Delete operations in SQLite, Rust will print 'Hello World!'. Is there a way for me to implement a hook like that? Thanks you. This is my Rust ...
shywoou's user avatar
0 votes
1 answer
43 views

How to infer the lifetime that Lifetime annotations in method(or function) definitions?

struct V<'a> { s: &'a mut String, v: Vec<&'a String> } impl<'a, 'b> V<'a> { pub fn set(&mut self, s: &'b String){ // self.s = s; ...
杨尚山's user avatar

1
2 3 4 5
787