Questions tagged [vec]

78 questions
0
votes
1 answer

How can I use Derived-macro attribute to store a generic struct in a Vec?

I'm working on implementing dynamic listeners for the communication layer of my embedded program. I want to store a Vec> in my Readers structure. Since T can change, I need to hide it behind a trait: Vec>…
totok
  • 1,436
  • 9
  • 28
0
votes
0 answers

Impulse response function (IRF) for VECM

I need help with irf plots. I am working with R and hope You can help me here. My VECM model consist of three endogenous variables and two exogenous variables. When I transform VECM to VAR using vec2var function and try to plot impulse response…
Laura_777
  • 55
  • 5
0
votes
2 answers

Construct a vector based on a repeating sequence

I am writing a sieve of Eratosthenes, for this you want to start a vector of booleans with odd indices true and even indices false. Currently my code for getting that is: let mut is_prime: Vec = vec![true;…
Pioneer_11
  • 670
  • 4
  • 19
0
votes
0 answers

Filter vec of trait objects by other trait and return all trait objects that implement given trait

I'm trying to filter a vec of trait objects by a trait and return a subset of the vec which contains all objects that implement given trait, similar to Bevys Query<>. I came up with this: pub fn filter<'a, T: Entity + Sized>(vector: &'a mut…
Joffi
  • 16
  • 2
0
votes
0 answers

Implement From> trait for Vec

I have a vector of a specific type. I can create a From trait that automatically converts a &str into the type. impl From<&str> for Type { fn from(value: &str) -> Self { Self { value: value.to_string() } } } I want to have a From…
wackazong
  • 474
  • 7
  • 18
0
votes
0 answers

Create a vector with known elements and a known capacity

Hi All I am trying to create a vector with some known elements and a known number of unknown elements. My current code is: let mut example: Vec = Vec::with_capacity(100); example.extend([1, 2, 3]) However, this seems clunky and feels like the…
Pioneer_11
  • 670
  • 4
  • 19
0
votes
1 answer

Rust iterate over ChunkExactMut -> use of moved value

i am a C++ Developer and try to learn Rust. I got a use of moved value error. I think it is because the ChunkExactMut iterator has no copy implemented. But the step_by function should create a new iterator (Rust documentation). fn step_by(self,…
0
votes
0 answers

vec.append not working, it tells me the list is still empty

My first post here, im working on a proyect and i need to append the data from CARGAR(n, vec) into the vec, i tried append but it doesnt work! I need help. Did i miss something? I randomly select the times and i make an average called suma_t, then i…
0
votes
5 answers

How to push additional element to Vec<&Vec>?

I am trying to accomplish something rather simple, but not sure how to do it in Rust. I have a Vec<&Vec>, something like the below example. [ ["a1", "b2", "c3"], ["d1", "e2", "f3"], ["g1", "h2", "i3"] ] I want to push an additional string at the…
kinxiel
  • 793
  • 1
  • 5
  • 7
0
votes
2 answers

When does a Vec reallocate if no default size is provided?

I'm currently learning Rust, and there are some aspects I would like to understand in order to be able to create more efficient code, so the question is, whats the default size of a Vec::new() and when does it reallocate if it exceeds the default…
andresvsm
  • 165
  • 1
  • 7
0
votes
1 answer

How to iterate through a HashMap,Vec>

As the title says I am trying to iterate through a HashMap of 2 vectors. my code is as follows: pub fn serialize_hashmap(data: &HashMap, Vec>) -> Result, String> { let mut serialized_data = Vec::new(); for (hash,…
Dyskord
  • 365
  • 5
  • 14
0
votes
0 answers

How to have a &[u8] variable reference somewhere other than the beginning of the array

I am trying to extract two 16 byte values from the front of a large buffer into 2 16 byte smaller buffers. I wrote a simple memcpy_safe() function: fn memcpy_safe(dest: &mut [u8], src: &[u8]) { let src_len = src.len(); let dest_len =…
Dyskord
  • 365
  • 5
  • 14
0
votes
0 answers

How to bulk insert into a vector in rust?

One of my function I'm inserting an arbitrary number of new elements into a vector at a given index. Because every insertion need to shift all the elements after the index, it is rather slow. Because of that I created an other vector, and tried to…
SurGe
  • 23
  • 3
0
votes
1 answer

Language Julia: convert vector in matrix

Who can help. To transform a vector into a one-dimensional matrix just run in Julia: a = copy(permutedims([1,2,3])) To transform the matrix "a" into a vector just use: b = copy(vec(a)) If you have a matrix "[1 2 3; 4 5 6]" to transform it into a…
SwFly
  • 25
  • 5
0
votes
1 answer

variable does not live long enough in a Vec>

I am trying to implement an algorithm like below. I don't know how to make the local variable long enough. May be my design is fully wrong. trait Metric { fn on_add(&mut self, _i: i32); } trait Update { fn update(&mut self, _i:…
Farbod PM
  • 122
  • 6