43,679 questions
1
vote
1
answer
25
views
Getting 'lifetime may not live long enough' while expecting 'cannot move out'
If I try to compile the following code
struct A<'a> {
value: &'a i32,
}
impl<'a> A<'a> {
fn f(&mut self) -> Option<&'a i32> {
Some(self.value)
...
0
votes
1
answer
36
views
Null in a dereferenced Stack Pointer in Rust on Cortex-M4 (nRF52833)
When developing a Rust no_std bootloader for my micro:bit v2.21 (Cortex-M4, nRF52833), I have encountered a weird error.
The bootloader jumps to the main application using cortex_m::asm::bootstrap(sp, ...
1
vote
2
answers
46
views
Comparing Swift's and Rust's function signatures
I want to check my understanding of how Swift and Rust handle function parameters.
From what I’ve seen, Swift has two main parameter modes:
Pass by value, immutable: f(x: T) and
Pass by reference, ...
0
votes
1
answer
30
views
Block execution till a Rust future is resolved on WASM without wasm bindgen
I am using a library (Macroquad) that has an async function with following signature:
async fn load_file(path: &str) -> Vec<u8>
This loads the file and returns the raw bytes.
Is there a ...
0
votes
1
answer
68
views
Cloning a static reference vs cloning nested value of static reference
I have an axum endpoint and currently cloning a nested struct from a static reference struct and retuning the response.
Cloning the nested value directly
#[derive(Clone, FromRef)]
pub struct ApiState {...
0
votes
0
answers
64
views
How to communicate via shared memory across threads? [closed]
I would like to achieve IPC communication via shared memory, possibly in a lock free manner on linux, akin to this crate.
Thread 1 writes to a region of memory, R_n
Thread 1 send a message to thread ...
0
votes
0
answers
18
views
fd is not pointing to valid bpf_map (BPF_PROG_LOAD syscall failed)
While testing my rust Aya xdp ebpf program i came across this error
Error: the BPF_PROG_LOAD syscall failed. Verifier output: fd 10 is not pointing to valid bpf_map
verification time 215 usec
stack ...
0
votes
1
answer
42
views
Actix variable path
Is there a way to rewrite: #[get("/status")] as #[get(status_strip_variable)]?
I cannot seem to find any example of path stored in a variable. Or maybe the use of get as a macro prevents us ...
0
votes
1
answer
25
views
How do I interpolate a type as string using quote! within a docstring in an attribute proc macro?
I have this macro definition:
//! Attribute macro to implement a discriminant method for enums with a specific representation type.
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::...
0
votes
0
answers
42
views
RuntimeError: unreachable executed from wasm-bindgen
My website has the following JS code running the generated WASM:
import init, {
solve_abrams_strogatz
} from './pkg/langshift.js';
async function run() {
await init();
console.log("...
-1
votes
0
answers
48
views
How can I clean up these wrapper traits?
I have a wrapper struct Batch<D> which is serializable with rkyv as long as various trait bounds are satisfied. Unfortunately those bounds are very ugly, so I want to push them into a wrapper ...
3
votes
0
answers
106
views
Why is cloning Trait Objects not supported, but possible via a crate?
I encountered what appears to be a very common stumbling block when learning Rust: that dynamic Trait objects cannot support Clone. I'll include a trivial example below. There is some excellent ...
4
votes
1
answer
57
views
If the return value of a function has the same lifetime as one of the arguments, then the return value is considered a borrow of the argument?
Where in Rust's specification does it say that if the returned reference of a function has the same lifetime as one of the reference arguments, then the returned reference is considered a borrow of ...
7
votes
1
answer
131
views
Is it UB to twice drop the same value of a type for which needs_drop() returns false?
Basically, the question is in the title. Assume we have a type T, for which std::mem::needs_drop::<T>() == false. Is it UB to drop twice a value of type T?
Here's an example: Consider the ...
0
votes
1
answer
63
views
How can I "template" or "functionalise" repeated behaviour?
In Rust I have the following syslog code:
use syslog::{Facility, Formatter3164};
fn main() {
let formatter = Formatter3164 {
facility: Facility::LOG_USER,
hostname: None,
...