Skip to main content
Filter by
Sorted by
Tagged with
3 votes
1 answer
98 views

I'm interested in the options for providing ownership or references to dependencies when doing dependency injection in Rust. I don't mean like a DI framework or anything like that, just the general ...
jacobsa's user avatar
  • 7,817
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
8 votes
2 answers
285 views

As far as I understand transferring ownership in Rust is a more expensive operation than transferring a value by shared or exclusive reference. As far as I understand from What is ownership? from the ...
LAST's user avatar
  • 93
0 votes
0 answers
42 views

The Error error[E0499]: cannot borrow `*self` as mutable more than once at a time --> src\scanner\mod.rs:103:17 | 45 | impl<'a> Scanner<'a> { | -- lifetime `'a` defined ...
Omega500's user avatar
0 votes
1 answer
75 views

I was trying to implement a system in Rust that has one struct that owns a value and another struct, which needs a reference to that value when created. It seems this is not really possible in any ...
Aatos Tapper's user avatar
0 votes
1 answer
152 views

Is there a way to avoid creating temporary variables a variable is captured in multiple closures: The move keyword in the closures is required It's fine to use any other container instead of Rc as ...
Andreas Tzionis's user avatar
-1 votes
1 answer
85 views

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 ...
Benoit Avril's user avatar
0 votes
0 answers
35 views

I have a struct to save data read from a socket connection. This struct has an array field buffer which provides space for the read data to be saved in. Now, I need to way to save which part of that ...
axolotlKing0722's user avatar
1 vote
2 answers
111 views

I have an object (let's call it A) that I want to store another object (let's say it has type B and is called m), which will be passed from the function that creates A. The creation of B is made by ...
Depenau's user avatar
  • 131
0 votes
0 answers
274 views

I am attempting to return the ownership percentage of the largest owner from several stocks using Bloomberg API in excel. Does anyone know of a relevant function to use? I have found "...
Erik Ibrekk's user avatar
-1 votes
1 answer
45 views

type NodePointer<T> = Option<Rc<RefCell<Node<T>>>>; #[derive(Debug)] struct Node<T> { val: T, next: NodePointer<T> } pub struct LinkedList<T> {...
Zero's user avatar
  • 1,909
0 votes
0 answers
41 views

I'm a relatively new Rust dev and this is an issue I've been running into consistently. Sometimes I have data stored within a Vector which I will later move into a new variable, but if the data isn't ...
Snowfallen's user avatar
0 votes
1 answer
167 views

I just started writing in Rust and I am writing a small program to learn Rust and the package Reqwest. Here's my little program. I don't understand why changing from HashMap<&str, &str> ...
stucash's user avatar
  • 1,288
1 vote
1 answer
145 views

Say I have a function that calls a Rust API that consumes a value. That API function returns a Result, potentially indicating an error. If the error happens, I need some information from the original ...
davidA's user avatar
  • 13.9k
0 votes
0 answers
45 views

An error occurs at a very simple place. When a reference enters a for loop, there is an implicit conversion to into_iter() on a mutable reference, and as we know, this also implicitly uses the ...
Алексей Яковец's user avatar
1 vote
2 answers
124 views

Consider the following code: fn print_or(opt: Option<()>, tail: Vec<i32>) -> Vec<i32> { opt.map_or(tail, |_| { println!("{:?}", tail); tail }) } ...
Some Name's user avatar
  • 9,730
0 votes
1 answer
86 views

I am working on a Rust project using rusb to interact with USB devices. I'm facing a lifetime management issue where I cannot return a struct containing a reference due to it referencing a local ...
Ganesh Rathinavel's user avatar
0 votes
1 answer
168 views

In Rust, a struct can have a method that takes ownership of the struct and moves it, making it illegal to use the struct again later, e.g. struct Foo {} impl Foo { fn consume(self) -> u32 { ...
kpozin's user avatar
  • 27.2k
0 votes
0 answers
59 views

The Issue I'm trying to implement an iterator that yields windows (i.e. slices) into a buffer owned by the iterator itself – for example, if the buffer contains [0, 1, 2, 3, 4, 5], the iterator might ...
obskyr's user avatar
  • 1,519
1 vote
2 answers
123 views

I have a class (A) that will own the memory for a set of instances of another class (B). A will store its instances of B as a set of std::unique_ptr<B>. I want A to be able to return a reference ...
SirXanderRoss's user avatar
2 votes
1 answer
138 views

I am learning Rust and am now taking a look at threads. I am trying to convert the following snippet into a parallelized execution: fn main() { let mut data: Vec<usize> = (1..22).collect(); ...
user171780's user avatar
  • 3,245
-1 votes
1 answer
67 views

I have the following code use euclid::Vector3D; fn main() { fn add_vectors<Unit>(a: Vector3D::<f64, Unit>, b: Vector3D::<f64, Unit>) -> Vector3D::<f64, Unit> { /...
user171780's user avatar
  • 3,245
0 votes
1 answer
55 views

The code below can work. #[derive(Debug)] struct Test{ str1 : Option<String>, str2 : Option<String>, } fn main() { let mut test = Test{ str1 : Some(String::from("...
CreatorHell's user avatar
0 votes
2 answers
173 views

I'm trying to create a chain of struct instances, like this: Struct_instance_a: id:1 prev:None Struct_instance_b: id:2 prev:Struct_instance_a etc.. But getting this error from the compiler: error[...
Karl Johannisson's user avatar
0 votes
0 answers
61 views

New rust user here. I'm trying to use yaml_rust to parse my config files, and spotted a difficulty. I am trying to keep Option<...> values to handle the possibility that a field is missing or ...
Riccardo Mazzei's user avatar

1
2 3 4 5
17