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 ...
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.
...
52
votes
6answers
10k views
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 ...
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; ...
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 ...
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?
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 ...
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.
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 ...
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 ...
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, ...
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?
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 ...
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>,
}
...
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 {
...
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 = ...
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 ...
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?
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 ...
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 ...
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 ...
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?
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 ...
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 ...
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: ...
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.
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 ...
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 ...
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 ...
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 ...
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 ...
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?
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};
...
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 ...
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, ...
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 ...
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
...
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 ...
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 ...
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;
...
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 = ...
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 ...
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 ...
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 ...
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)
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 ...
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;
}
...
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 ...
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 ...
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?