Questions tagged [vec]
78 questions
1
vote
2 answers
Panic if the capacity of a vector is increased
I am working on implementing a sieve of atkins as my first decently sized program in rust. This algorithm takes a number and returns a vector of all primes below that number. There are two different vectors I need use this function.
BitVec 1 for…

Pioneer_11
- 670
- 4
- 19
1
vote
1 answer
Rust: does Vec auto convert to [T]?
I'm new to Rust and I'm confused with Vec and slice.
Here is my scene:
fn funA() {
let v1: Vec = vec![1, 2, 3];
funB(&v1); // question_A
v1.iter(); // question_B
}
fn funB(slice: &[i32]) {
// slice type is &[i32] by…

Seven
- 13
- 2
1
vote
2 answers
Convert Take to Vec or to &[T]
I have a struct called Cell
pub struct Cell {
x: X, // Some other struct
y: Y, // Some other struct
weight: usize,
}
I was trying to select the top preference cell out of some Row (a collection of Cells).
// Return the top n-matching…

محمد جعفر نعمة
- 1,045
- 1
- 11
- 33
1
vote
1 answer
Allow Vec of custom type to be joined with &str
I want a Vec to be joinable by &str.
Here is a minimal example of what I've tried so far:
#[derive(Debug)]
struct Item {
string: String,
}
impl Item {
pub fn new(string: impl Into) -> Self {
Self {
…

Richard Neumann
- 2,986
- 2
- 25
- 50
1
vote
1 answer
Rust views over a shared refcounted array
I am trying to implement multiple "slices" over a shared array of objects. My solution is to morally make a
struct MySlice{ shared_data: Rc<[T]> , beg: usize, len: usize }
I want to be able to implement both
impl From> for MySlice {…

fakedrake
- 6,528
- 8
- 41
- 64
1
vote
2 answers
Is converting between String & Vec a zero-op in --release binary
String & Vec are almost the same to me, though String guarantees to have valid UTF-8 content, which is often useful.
However, being in unsafe context, does it really take any machine operation to cast between two of them if no check is…

Sir
- 337
- 1
- 7
1
vote
1 answer
How to sort a vector containing structs?
Lets say I have some code like:
struct GenericStruct {
a: u8,
b: String,
}
fn sort_array(generic_vector: Vec) -> Vec {
// Some code here to sort a vector.
todo!();
}
fn main() {
let some_words =…

user13149230
- 17
- 5
1
vote
1 answer
Can you build a structopt parser that takes the rest of the command line (or multiple arguments)?
structopt has a neat feature where it can it accept a typed argument for Vec that will gobble the rest of the command line.
#[structopt(long, short)]
values: Vec,
It also has the ability to accept a type you create,
If the field type does…

Evan Carroll
- 78,363
- 46
- 261
- 468
1
vote
1 answer
signal: aborted (core dumped), making a two sum pair from a vector
This is the question I'm trying to solve:
Write findTwoSumPair, which takes in a vector of integers and a
target sum, and returns a pair that represents two distinct indices
of elements that sum up to the target value (with indexes sorted).
There…

Funmi Orekoya
- 11
- 3
1
vote
1 answer
How to create ROM with VecInit(Array()) in Chisel?
I'm trying to declare a «rom» with VecInit() like it :
val GbColors = VecInit(Array(GB_GREEN0, GB_GREEN1, GB_GREEN2, GB_GREEN3))
With GB_GREENx declared like it :
class VgaColors extends Bundle {
val red = UInt(6.W)
val green = UInt(6.W)
…

FabienM
- 3,421
- 23
- 45
1
vote
2 answers
Why do I get an empty vector when splitting a file by lines and then words?
I'm trying to read a text file with Rust where each line has two words separated by a whitespace. I have to get the length of the first word:
use std::fs;
fn main() {
let contents = fs::read_to_string("src/input.txt").expect("Wrong file…

tnas
- 510
- 5
- 16
1
vote
0 answers
How do I conduct restricted VECM in statsmodels for hypothesis testing?
I am new to statsmodel and as above, would like to know how I can conduct restricted VECM in statsmodels for hypothesis testing?
Additionally, is there a way I can find the roots of a VECM model to see if it is stable in statsmodels? I have looked…

OGARCH
- 97
- 1
- 4
1
vote
0 answers
[h2o-3 ]Is there an existing solution to swaping two vectors in h2o-3?
Lets say theres a Frame fr consisting of 3 vectors with column names "a" "b" "c". I have an MRTask giving me a new vector. Vec new_vec_a = FooReturningNewVec(fr.vec("a")). Now I want to swap fr.vec("a") with new_vec_a.
Can I use an already existing…

ard
- 43
- 4
1
vote
0 answers
Reducer that push member into Vec in Rust
I am looking for an equivalent version of this function, either from std or from external crate.
fn add(v: Vec, item: T) -> Vec {
v.push(item);
v
}
The purpose of this function is to use it with some reducer (in my case, I need it…

copycat1024
- 19
- 1
1
vote
1 answer
Why doesn't Rust's ChunksExact have a size known at compile-time
I'd like to copy one Vec into another, in chunks of [u8; 4] assigning the first 3 element of each chunk only(leaving the 4th alone). This seems like a practical way to go about it:
let input_pix: Vec = ...;
let mut output_pix: Vec =…

Thomas Matecki
- 629
- 5
- 20