43,916 questions
0
votes
0
answers
18
views
Simultaneous mutable references to 2 or more elements of a struct in rust [duplicate]
Hi to the rust community. I have 2 somewhat related questions and I am hoping for answers.
The 1st question is: Let's assume that I have a struct as shown below:
pub struct MyStruct {
a: i64,
...
0
votes
1
answer
30
views
Make trait with async methods dyn compatible (object safe)?
I coded an app that should sync git repos to our company's network hosts. Since I'm also testing the facilities I thought I'd naturally use the strategy pattern and have the executing function use ...
Best practices
0
votes
1
replies
29
views
How should I store a dyn FnMut in a struct?
I'm trying to make a struct that has dynamic methods by storing FnMuts in the struct. The FnMuts would be a function written in a scripting language like Python or Lua, but there might be some cases ...
-3
votes
1
answer
54
views
RENEGOTIATING error when using RUSTLS library and receiving RCPT TO: command from OPENSSL [closed]
I am trying to use RUSTLS in my SMTP listener and I am getting error:
RCPT TO: <[email protected]>
RENEGOTIATING
40D7CFBDBE7D0000:error:0A00010A:SSL routines:can_renegotiate:wrong ssl version:../ssl/...
4
votes
1
answer
73
views
Deserialize the same JSON field into two different struct fields
I'm trying to deserialize a JSON object, and use the value from one of its fields for two different fields in the Rust struct. I've seen similar questions to this, but all of them were trying to do ...
-4
votes
0
answers
43
views
The type of a function does not implement a trait which is implemented by the same function pointer type? [duplicate]
I have this reduced example code:
fn double(x: i32) -> i32 {
x * 2
}
trait Trait {
fn go(&self, x: i32) -> i32;
}
impl Trait for fn(i32) -> i32 {
fn go(&self, x: i32) -&...
4
votes
2
answers
101
views
How to optimize enum size?
I'm building a small regex VM that matches text with bytecode-like instructions. Take the following enum:
pub type Pc = usize;
pub enum Inst {
Char(char, Pc),
Range(char, char, Pc),
Any(...
4
votes
1
answer
147
views
Flipping line of 4-Byte pixels horizontally
I must flip some lines of pixels around their centers (not the whole image).
My first solution in simple, safe Rust was this:
/** It's a square, each side (width & height) is PIXELS_PER_SIDE long.
...
1
vote
1
answer
78
views
mock feature in SeaORM v1.1.19 makes DatabaseConnection lose the trait to clone it
Im doing a Actix Web rust backend with SeaORM, I finished and it works fine, so I'm doing some tests, SeaORM has a mock feature, which you can enable in the Cargo.toml file, but enabling it makes the ...
0
votes
0
answers
92
views
Docker with WasmEdge runtime creates container but fails to start on Windows (Status: Created) [closed]
I am trying to run a Rust application compiled to WASM inside Docker using the WasmEdge runtime. I have enabled the "Use containerd for pulling and storing images" and "Enable Wasm"...
-5
votes
0
answers
76
views
How can I migrate the Tapp AMM exchange on move smart contract? [closed]
Can anyone teach me what is the issue in the following code lines. This is tapp exchange migration script in move smart contract.
let data = vector::empty<u8>();
// pool id (32 bytes)
vector::...
Best practices
0
votes
1
replies
86
views
Rust: Iterator<(key, value)> to HashMap<Key, Vec<Value>> the functional way
I have a vector of key-value pairs, where keys can be duplicate, or rather, I have an iterator that I eventually collect to that vector. I need to get a HashMap with those keys, but vectors of values ...
0
votes
0
answers
77
views
Add custom events in components
Dioxus components can add EventHandlers on predefined Node attributes
eg:
fn app() -> Element {
let mut moveCount = use_signal(|| 0);
rsx! {
h1 { "Mouse mouvement counter: {...
1
vote
1
answer
95
views
How do I display a continuation prompt with `rustyline`?
I'm writing a simple REPL for a language with rustyline, and I'm trying to support multiline input using ^J. How do I get rustyline to display a read-only continuation prompt while inserting a ...
1
vote
1
answer
97
views
How to split a slice at a given index, then move the remaining elements into a boxed slice without copying or cloning?
We have a boxed slice of an arbitrary type T. I'd like to slice it at a given index, then move the remaining elements after the index into a new Box<[T]>. It's fine if the original Box<[T]>...