Skip to main content
0 votes
2 answers
78 views

I am writing a scripting language in rust, and I'm pretty new to the language. When I compile source into byte code I move the compiled symbols (Chunk) out of the function. I am also lazy and don't ...
NongusStudios's user avatar
3 votes
0 answers
77 views

I am trying to develop a linear algebra library in rust. So, as part of it I am writing code that iterates through a n-dimensional array and returns mutable references. It's like writing a view for a ...
SpatialFuel's user avatar
4 votes
2 answers
123 views

This is a pattern I want to be able to use in my code to have global variables that contain non-static references. Is it memory safe? If not, how can I make it so? use std::cell::Cell; pub struct ...
Wesley Jones's user avatar
5 votes
1 answer
180 views

While trying to write an API inspired by the structure of std::thread::scope, I ran across the following problem. This function compiles fine (playground): use std::marker::PhantomData; pub struct ...
jacobsa's user avatar
  • 7,875
5 votes
1 answer
132 views

I am using the winnow crate to write a parser and am struggling with adding tests due to lifetime conflicts. The basic setup I have is a stateful stream: // The primary stream type type SStream<'i, ...
JohnT's user avatar
  • 115
1 vote
1 answer
119 views

I'm aware it is not much possible nor recommended to have both a field that owns a value, and another one that stores a reference to the same value in a struct. I was experimenting a bit with a more ...
pjsph's user avatar
  • 11
0 votes
1 answer
141 views

Edit: added a second part of the question below. I am getting the error "borrow of moved value" here, but the thing being moved is an &mut Containee, so I didn't expect it to cause a ...
knutaf's user avatar
  • 113
2 votes
1 answer
68 views

I'm trying to create a little utility that simplifies the execution of repetitive work. This would be almost trivial in memory managed languages, but gets unnervingly complex in Rust. I'd call myself ...
NoBullsh1t's user avatar
4 votes
2 answers
189 views

I want to understand lifetimes and the elision rules better. Suppose we want to extend a Vec<i32> (really Vec<&i32>) fn extend_vector( v: &mut Vec<&i32>, x: &...
Markus Klyver's user avatar
5 votes
1 answer
79 views

I have the following code: fn test() -> (impl FnMut(&mut u8), impl FnMut(&mut u8)) { let a = |v: &mut u8| {*v = 0}; let b = move |v: &mut u8| { a(v); println!("{}&...
Nils Oskar Nuernbergk's user avatar
1 vote
2 answers
102 views

I wanted to implement the Merge Sort algorithm, but I am having trouble with the borrow checker rules. The compiler gives me the hint: cannot borrow *lst as immutable because it is also borrowed as ...
Finn's user avatar
  • 105
1 vote
1 answer
66 views

Context I'm trying to learn Rust by just reading the book and working through the problems in Advent of Code (the 2024 edition). Just to make it harder, I decided to practice TDD while I do it. To ...
Juan F. Meleiro's user avatar
1 vote
2 answers
89 views

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, ...
Xander's user avatar
  • 11
4 votes
1 answer
77 views

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 ...
palapapa's user avatar
  • 1,051
0 votes
0 answers
74 views

In Rust, how can I define&manipulate objects that cannot be just copied bit-by-bit when they're moved? For example, an object that contains a relative pointer (i.e. a pointer whose target is ...
Stefan's user avatar
  • 28.8k

15 30 50 per page
1
2 3 4 5
127