Questions tagged [rust]

Rust is a language designed for writing highly reliable and fast software in a simple way. It can be used from high-level code down to hardware-specific code, and from big irons to tiny devices.

9
votes
1answer
74 views

Compiler forces me to implement trait method but the `Self` trait bound on method is never satisfied for my type

I have a trait Foo. I want to force implementors to define a method, if those implementors implement another trait (Clone in this example). My idea (Playground): trait Foo { // Note: in my real ...
0
votes
0answers
18 views

Creating a static library with Rust to link it to an arm-none-eabi C code firmware

I have an existing C firmware for a Nordic nRF52832 BLE microcontroller. I'd like to link some new code to it, that I wrote in Rust. When I try to do so, the linker complains that I have two ...
-1
votes
0answers
37 views

How do I make a dynamic index to get the value of a tuple?

In Python, I learned that I can retrieve a tuple value by a dynamic index: data = (1,2,3,4) data[0] for a in range(len(data)): print(data[a]) The output: 1 2 3 4 how to do this in Rust? I ...
0
votes
1answer
38 views

How to make a generic of generic with trait?

pub struct Triangle<T: Float + std::clone::Clone, V: vector::Vector<T>> { point1: V, point2: V, point3: V, } This chunck of code doesn't compile because T isn't used (...
-1
votes
2answers
55 views

Why does rust produce completely different assembly with and without pub and #[no_mangle]?

The rust code in question is: #[no_mangle] fn add(a: isize, b: isize) -> isize { a + b } It produces the following assembly code when used with rustc command rustc add.rs --crate-type=lib --...
-1
votes
0answers
53 views

my algorithm uses too much memory with the rayon crate

I'm implementing the Pythagorean Triplet algorithm. I use rust V1.33 and rayon V1.03. My sequential algorithm is the following: use std::collections::HashSet; pub fn find(sum: u32) -> HashSet<...
1
vote
0answers
30 views

How can i make a piece of running code timeout? [duplicate]

I'm trying to get some piece of code to run for at most timeout duration. In other words I want a piece of code to either complete in the given time constraint or be interrupted. The concrete code ...
1
vote
0answers
28 views

How do I check for features set in Rust during compilation?

I am trying to use Rusts feature to conditionally compile a module in my crate and also use it only when a feature is enabled. The conditional compilation works fine when the feature is set, but ...
0
votes
0answers
27 views

Not able to install rust successfully on Windows 10

I am trying to install rust which is failing with following error: Any one has faced same issue before on windows 10? Any help appreciated! info: syncing channel updates for 'stable-x86_64-pc-...
0
votes
1answer
42 views

Is there a more concise way to format .expect() message?

I currently have to use this to format a .expect() message: fn main() { let x: Option<&str> = None; x.expect(&format!("the world is ending: {}", "foo")[..]); } Is there a less ...
-1
votes
0answers
52 views

How to rewrite this function with T in Rust? [duplicate]

A count sort function: pub fn count_sort(v: Vec<i32>) -> Vec<i32> { let mut vc = vec![0; 32]; let mut vn: Vec<i32> = Vec::new(); for i in v { vc[i as usize] +=...
-1
votes
2answers
72 views

can isize and usize be different in rust?

Can isize and usize be different? Both of them can be used for memory size, index, offset. Since usize is used for arrays why don't we just have usize I am new to Rust so this might be a basic ...
0
votes
0answers
31 views

Why is it the case that multiple libraries aren't allowed from the same project in Cargo? [duplicate]

Using [[bin]] in Cargo.toml allows me to compile multiple binaries from the same source of a Rust project. But I want to deploy multiple web-components from the same source, and web-components are ...
4
votes
1answer
44 views

What is the equivalent of Java's transient in Serde?

I am interested in making a variable not automatically serialized (e.g., by Serde) with the use of a keyword like Java's transient, but in Rust. I need this to store passwords. Of course, I could ...
3
votes
1answer
54 views

How do I use a specific edition of Rust?

I know there are currently two editions of Rust (2015 and 2018), how can I tell cargo and rustc which one I want to use?

15 30 50 per page