Highest Voted 'rust' Questions - Stack Overflow
Description: Q&A for professional and enthusiast programmers

### current community

- chat blog
  Stack Overflow
- Meta Stack Overflow
- Stack Overflow Careers

### your communities

Sign up or log in to customize your list.

### more stack exchange communities

Stack Exchange
sign up log in tour help

- Tour Start here for a quick overview of the site
- Help Center Detailed answers to any questions you might have
- Meta Discuss the workings and policies of this site

stack overflow careers
Stack Overflow

# Tagged Questions

info newest frequent votes active unanswered

Rust is a systems programming language focused on three goals: safety, speed, and concurrency. It maintains these goals without needing a garbage collector, making it a useful language for a number of use cases other languages aren't good at: embedding in other languages, programs with specific ...

learn more… | top users | synonyms

67
votes
8answers
23k views

### Applications and libraries written in Rust [closed]

Although Rust is still under heavy development, there should exist examples of applications and libraries at least partially written in Rust. Unfortunately I am unable to find such examples. ...
rust
asked Feb 19 '12 at 14:39
Atom
11k34157
52
votes
6answers
10k views

### How to debug Rust programs? [closed]

How can we debug Rust programs?
rust
asked Apr 8 '13 at 5:30
macropas
1,6351221
51
votes
9answers
10k views

### How to access command line parameters?

The rust tutorial does not explain how to take parameters from the command line. fn main() is only shown with an empty parameter list in all examples. So what is the correct way of accessing command ...
rust
asked Mar 25 '13 at 15:59
shutefan
6603915
48
votes
6answers
4k views

### Why are explicit lifetimes needed in Rust?

I was reading the lifetimes chapter of the Rust book, and I came across this example for a named/explicit lifetime: struct Foo<'a> { x: &'a i32, } fn main() { let x; ...
pointers rust static-analysis lifetime
asked Jul 24 at 11:15
jco
5,4001145114
46
votes
1answer
1k views

### What is the difference between traits in Rust and typeclasses in Haskell?

Traits in Rust seem at least superficially similar to typeclasses in Haskell, however I've seen people write that there are some differences between them. I was wondering exactly what these ...
haskell rust
asked Jan 24 at 7:50
LogicChains
719313
44
votes
2answers
4k views

### Rust String versus str

I've been awhile from Rust and a new wild type String appeared. So I'm wondering what are the differences? When does one use String instead of str and vice versa? Is one of them getting deprecated?
string rust
asked Jun 11 '14 at 8:29
Daniel Fath
2,50711742
40
votes
1answer
2k views

### What are Rust's exact auto-dereferencing rules?

I'm learning/experimenting with Rust, and in all the elegance that I find in this language, there is one peculiarity that baffles me and seems totally out of place. Rust automatically dereferences ...
pointers reference rust dereference formal-semantics
asked Feb 14 at 20:31
kFYatek
27828
36
votes
3answers
4k views

### What is typestate?

What does TypeState refer to in respect to language design? I saw it mentioned in some discussions regarding a new language by mozilla called Rust.
rust language-design rust-obsolete
asked Jul 9 '10 at 5:22
Brad The App Guy
14.3k22954
34
votes
2answers
6k views

### Move vs Copy in Rust

Let's say I have this struct struct Triplet { one: int, two: int, three: int, } If I pass this to a function it is implicitly copied. Now sometimes I read that some values are not ...
rust
asked Jun 16 '14 at 22:47
Christoph
6,30953770
33
votes
1answer
1k views

### Running Boehm GC in multiple threads independently

I'm experimenting with writing some bindings to the Boehm GC for Rust. Some background: Rust is designed to be a high-concurrent language, and a result of this design is having the ability to ...
c multithreading garbage-collection rust boehm-gc
asked Jan 4 '14 at 14:06
huon-dbaupp
31.1k358103
32
votes
7answers
14k views

### Rust Web Frameworks [closed]

The goal of Rust is to be a good language for the creation of large client and server programs that run over the Internet. Rust description on wikipedia I was looking for web frameworks for rust, ...
webserver web-frameworks rust
asked Jul 17 '13 at 10:01
Nikolay Fominyh
3,54422463
25
votes
3answers
5k views

### How do I print the type of a variable in Rust?

I have this code snippet: let mut my_number=32.90; I need to know the type of my_number. Using type and type_of did not work; is there any other way I can print the number's type?
rust
asked Feb 13 '14 at 6:49
user2431012
12926
24
votes
3answers
2k views

### println! doesn't work in rust unit tests?

I'm using rust 0.11 and implemented the following method and unit test: fn read_file(path: &Path) { /* let mut file = BufferedReader::new(File::open(path)); for line ...
rust println
asked Aug 3 '14 at 16:10
ruipacheco
1,40222045
23
votes
2answers
2k views

### What is the overhead of Rust's Option type?

In Rust, pointers can never be null, so in case where you actually need null, such as a linked list, you use the Option type: struct element { value: int, next: Option<~element>, } ...
performance rust null-pointer
asked May 12 '13 at 5:59
Thilo
132k46278420
22
votes
1answer
5k views

### How do you implement a custom 'fmt::Debug' trait in rust?

I presume you do something like this: use uuid::Uuid; use std::fmt::Formatter; use std::fmt::Debug; #[deriving(Debug)] struct BlahLF { id: Uuid } impl BlahLF { fn new() -> ~BlahLF { ...
rust
asked Mar 7 '14 at 6:52
Doug
4,27833161
21
votes
2answers
6k views

### What is this unwrap thing: sometimes it's unwrap sometimes unwrap_or

Google doesn't returns any good results. I've encountered it reading http://www.rustforrubyists.com/book/book.html i.e. let mut reader = BufferedReader::new(io::stdin()); let input = ...
rust
asked Jan 21 '14 at 12:06
rofrol
790816
21
votes
1answer
5k views

### Lifetimes in Rust

Occasionally I've found myself wanting to write functions that can be called in either of two ways: // With a string literal: let lines = read_file_lines("data.txt"); // With a string pointer: let ...
rust
asked Jul 5 '13 at 14:00
Daniel
4,94611951
19
votes
2answers
2k views

### What is monomorphisation with context to C++?

Dave Herman's recent talk in Rust said that they borrowed this property from C++. I couldn't find anything around the topic. Can somebody please explain what monomorphisation means?
c++ rust
asked Jan 7 '13 at 3:47
unj2
11.4k42153286
17
votes
3answers
3k views

### How do I transform &str to ~str in Rust?

This is for the current 0.6 Rust trunk by the way, not sure the exact commit. Let's say I want to for each over some strings, and my closure takes a borrowed string pointer argument (&str). I ...
string pointers rust
asked Mar 13 '13 at 7:35
Ross
683717
16
votes
5answers
9k views

### How to Read User Input in Rust?

I'm wondering how to read user input in Rust. I intend to make a tokenizer, so first thing I need is to read every single line the user types and stops reading once the user presses <ctrl-D> I ...
input io rust
asked Nov 27 '12 at 7:23
BeyondSora
1,2501021
16
votes
3answers
5k views

### How do I make an HTTP request from Rust?

How can I make an HTTP request from Rust? I can't seem to find anything in the core library. I don't need to parse the output, just make a request and check the HTTP response code. Bonus marks if ...
http rust
asked Jan 4 '13 at 9:50
Alex Dean
5,38233860
16
votes
1answer
2k views

### Can rust library be used from another languages in a way c libraries do?

Writing such library will I have to sacrifice std? How, for example, will do I write python bindings to rust library, if possible?
dll rust shared-libraries
asked May 21 '14 at 10:52
Moonwalker
530928
16
votes
3answers
5k views

### any one tried Mozilla's programming language Rust Yet? [closed]

Mozilla is designing a new programming language called Rust , has anyone give it a try? what makes it different from other programming languages like C# if someone gave it a try tell us what you ...
programming-languages mozilla rust
asked Dec 11 '10 at 22:57
Saif al Harthi
2,25411020
16
votes
2answers
5k views

### Does/Will Rust support functional programming idioms?

As Rust gets fleshed out more and more, my interest in it begins to pique. I love the fact that it supports algebraic data types and in particular matching of those, but are there any thoughts made on ...
functional-programming rust
asked Aug 22 '13 at 7:52
Sebastian
580720
15
votes
2answers
2k views

### References to traits in structs

Lets say I have a trait Foo pub trait Foo { fn do_something(&self) -> f64; } and a struct which references that trait pub struct Bar { foo : Foo, } Trying to compile I get error: ...
rust
asked Oct 6 '14 at 8:25
neil danson
28219
15
votes
5answers
9k views

### How do you make a range in Rust?

The docs don't say how, and the tutorial completely ignores for loops.
loops for-loop range rust
asked Feb 14 '12 at 5:03
mcandre
7,99043675
15
votes
2answers
236 views

### How to Iterate Over an Array?

I'm new to Rust and I'm trying to write a program that involves filtering and folding over arrays. I've been using TRPL as a reference, but I don't understand what happens when I form iterators over ...
rust
asked May 26 at 19:19
WillEngler
8515
15
votes
1answer
307 views

### Can libraries be distributed as a binary, so the end user cannot see the source code?

Is it possible to compile a Rust library crate so that the user can't see the source code but can still use the library? If it is, are all the generics provided as "Source code" or some IR, or does ...
rust
asked Jan 17 at 12:41
J V
3,46311527
15
votes
1answer
3k views

### Using Rust, is there a faster/shorter way to initialize variables in a struct?

In the following example, I would much prefer to assign a value to each field in the struct in the declaration of the fields. Alternatively, it effectively takes one additional statement for each ...
rust
asked Oct 29 '13 at 5:21
Brian Oh
9831123
15
votes
1answer
137 views

### Can I mark a function as deprecated?

I'd like to mark functions/methods as deprecated. I tried to apply the deprecated attribute: #[deprecated] fn old_way_of_doing_it() { but this yields an error: error: stability attributes may ...
rust
asked Jun 10 at 13:32
Fraser
27.1k56393
14
votes
1answer
2k views

### Rust FFI C string handling

I'm playing around a bit with the Rust FFI, and now I'm trying to get a C string returned by a C library, and convert it to a Rust string. My code: mylib.c const char* hello(){ return "Hello ...
c ffi rust
asked Jun 10 '14 at 16:07
Dirk
465617
14
votes
1answer
8k views

### How do I convert a Vector of bytes (u8) to a string in Rust?

I am trying to write simple TCP/IP client in Rust and I need to print out my buffer I got from the server. How do I convert the u8 vector to a String for printing?
string vector rust
asked Sep 29 '13 at 10:03
Athabaska Dick
994816
14
votes
1answer
193 views

### Convert Rust vector of tuples to a C compatible structure

Following these answers, I've currently defined a Rust 1.0 function as follows, in order to be callable from Python using ctypes: use std::vec; extern crate libc; use libc::{c_int, c_float, size_t}; ...
python rust ctypes
asked Jun 22 at 16:03
urschrei
6,22241636
14
votes
2answers
6k views

### Is it possible to use global-variables in Rust?

I know that in-general global-variables are to be avoided. Nevertheless, I think in a practical sense, it is sometimes desirable (in situations where the variable is integral to the program) to use ...
global-variables rust
asked Oct 26 '13 at 9:39
Brian Oh
9831123
13
votes
3answers
4k views

### Split a module across several files

I want to have a module with multiple structs in it, each in its own file. Using a Math module as an example: Math/ Vector.rs Matrix.rs Complex.rs I want each struct to be in the same module, ...
module rust
asked Mar 23 '14 at 20:53
EpicPineapple
442622
13
votes
3answers
819 views

### Split stacks unneccesary on amd64

There seems to be an opinion out there that using a "split stack" runtime model is unnecessary on 64-bit architectures. I say seems to be, because I haven't seen anyone actually say that, only dance ...
multithreading go 64bit callstack rust
asked Oct 18 '13 at 12:50
brooks94
642726
13
votes
3answers
4k views

### How do you use parent module imports in rust?

Hm, this is covered in the rust tutorial, but I can't actually make it work. If you have a directory structure like this: src/main.rs src/module1/blah.rs src/module1/blah2.rs src/utils/logging.rs ...
rust
asked Jan 4 '14 at 14:17
Doug
4,27833161
13
votes
2answers
183 views

### Writing a Rust unit test that passes on panic?

Suppose that a function in rust panics under some condition (through the panic() macro). I wish to write a test case to validate whether the function is panicing or not under those conditions. I ...
unit-testing rust
asked Oct 20 '14 at 15:46
Shailesh Kumar
2,89411439
13
votes
3answers
1k views

### Composition operator and pipe forward operator in Rust

Do both the composition and pipe forward operators (like in other languages) exist in Rust? If so, what do they look like and one should one be preferred to the other? If one does not exist, why is ...
rust
asked Jun 11 '13 at 22:34
Phlox Midas
659620
13
votes
1answer
127 views

### No error for two traits implementing the same method

According to the docs, Rust should complain if I try to call a method provided by two different traits like this: trait Foo { fn f(&self); } trait Bar { fn f(&self); } struct Baz; ...
rust mio
asked Jun 7 at 21:21
michas
8,80212157
13
votes
1answer
351 views

### Generating strings and identifying substrings is very slow

I'd like to benchmark certain operations in Rust, but I seem to be having some trouble: fn main(){ let needle = (0..100).map(|_| "b").collect::<String>(); let haystack = ...
string substring rust
asked May 16 at 6:57
Tasos Laskos
1106
13
votes
3answers
852 views

### Rust struct can borrow “&'a mut self” twice, so why can't a trait?

The following Rust code compiles successfully: struct StructNothing<'a>; impl<'a> StructNothing<'a> { fn nothing(&'a mut self) -> () {} fn twice_nothing(&'a ...
iterator rust lifetime
asked Oct 4 '14 at 11:55
emk
33.1k32742
13
votes
1answer
1k views

### How to handle blocking i/o in Rust, or long running external function calls in general

I need to read data provided by an external process via a posix filedescriptor in my Rust program. The fd connection is kept up a very long time (hours) and the other side passes data to me from time ...
io task ffi rust
asked May 29 '13 at 15:53
Zargony
4,89912538
12
votes
2answers
2k views

### Why “explicit lifetime bound required” for Box<T> in struct?

I'm trying to compile this rust code: trait A { fn f(&self); } struct S { a : Box<A> } and I'm getting this error: a.rs:6:13: 6:14 error: explicit lifetime bound required a.rs:6 ...
rust
asked Sep 21 '14 at 12:16
Eugene Zemtsov
755
12
votes
2answers
2k views

### How to convert String into &'static str

I wonder how do I convert a String (formerly StrBuf) into a &str. More specifically, I would like to convert it into a str with a static lifetime (&'static str)
rust
asked May 31 '14 at 23:30
Christoph
6,30953770
12
votes
2answers
934 views

### In rust, what is the idiomatic equivalent of Haskell's [n..m]?

How do I produce a list containing all the integers in Rust ? I'm looking for the equivalent of Haskell's [n..m] or python's range(n, m+1) but can't find anything. I'm aware of the int::range ...
rust
asked Apr 5 '13 at 14:08
Fabien
2,38511336
12
votes
1answer
98 views

### Does println! borrow or own the variable?

I am learning Rust right now and am confused with borrowing and ownership. In the Rust documentation about reference and borrowing let mut x = 5; { let y = &mut x; *y += 1; } ...
rust ownership
asked May 26 at 5:48
kevinyu
976
12
votes
1answer
3k views

### What is #[warn(unstable)] about in Rust?

I have a really simple cat function written in the Rust 1.0 alpha. use std::io; fn main(){ let mut reader = io::stdin(); loop { let input = reader.read_line().ok().expect("Failed to ...
io rust
asked Jan 10 at 4:05
wegry
468518
12
votes
1answer
1k views

### What does “cannot move out of indexed content” mean?

I am playing with Rust, and I'm trying to access the first command line argument with this code: use std::os; fn main() { let dir = os::args()[1]; println!("Hello, world!"); } And I get ...
rust
asked Jan 12 at 14:59
Rory
11k28110172
11
votes
2answers
2k views

### In Rust, how do I invoke a system command and capture its output?

Is there a way to invoke a system command, like ls or fuser in Rust? How about capturing its output?
rust
asked Jan 9 '14 at 3:55
quux00
3,46512045
1 2 3 4 5 … 56 next
highest voted rust questions feed