Questions tagged [rust-obsolete]

Versions of Rust predating 1.0 can have drastically different syntax and semantics. Some questions for these versions no longer apply to a stable version of Rust but are of historical interest.

Filter by
Sorted by
Tagged with
3 votes
1 answer
529 views

What is "0is" notation in Rust?

As seen in this repository: https://github.com/ReactiveX/RxRust/blob/master/src/lib.rs#L110 let gen = move |:| { let it = range(0is, 20is); // ~~~ ~~~~ let q = Box::new(...
  • 411
3 votes
1 answer
622 views

What is a modern analog to the deprecated std::raw::Repr?

I'm looking through some old (~2014) Rust code and I'm seeing this code block: fn compile(self, func:&UncompiledFunction<'a>) -> &'a Val { unsafe { use std::raw::Repr; ...
  • 3,468
3 votes
1 answer
525 views

Unable to build Hyper - invalid character `-` in crate name

I am trying to run the hyper example listed on the Github readme. extern crate hyper; use std::io::Write; use hyper::Server; use hyper::server::Request; use hyper::server::Response; use hyper::net::...
18 votes
2 answers
5k views

Why does #[derive(Show)] not work anymore?

With today's Rust nightly the following code doesn't compile anymore: #[derive(Show)] enum S { A, B } fn main() { println!("{}", S::A); } Instead it gives me the following error message:...
  • 3,973
9 votes
1 answer
675 views

How to rewrite code to new unboxed closures

Can somebody help me to rewrite this piece of code with new unboxed closures: struct Builder; pub fn build(rules: |params: &mut Builder|) -> Builder { let mut builder = Builder::new(); ...
6 votes
2 answers
393 views

How is 999µs too short but 1000µs just right?

When I run the following code, I get some output: use std::thread::Thread; static DELAY: i64 = 1000; fn main() { Thread::spawn(move || { println!("some output"); }); std::io::...
  • 11.9k
2 votes
1 answer
2k views

How to get square root in Rust 0.13.0?

In 0.13.0-nightly the following code won't compile: fn main() { let a = (10.5f64).sqrt(); } I get the error: error: type `f64` does not implement any method in scope named `sqrt` What am I ...
  • 6,750
2 votes
1 answer
359 views

Rust won't narrow down types? Or did I make a mistake

Trying to write something similar to Haskell's HList, with the ability to search by type. With the below code, in play.rust-lang.org version rustc 0.13.0-dev (567b90ff0 2014-12-13 20:02:15 +0000) I ...
  • 85
6 votes
3 answers
8k views

Generating secure random numbers in Rust

I can see I have to import like this: use std::io::IoResult; use std::num::{Int, ToPrimitive}; use std::rand::{OsRng, Rng}; Then make a new instance of OsRng, and try to generate a new u32 int from ...
  • 1,548
1 vote
1 answer
163 views

Type information of a proc() cannot be inferred if not passed into spawn()

This compiles: use std::num::pow; pub fn main() { let (tx, rx): (Sender<u64>, Receiver<u64>) = channel(); let square_tx = tx.clone(); let square = proc() { let mut x ...
  • 12.5k
9 votes
1 answer
5k views

Declaring array using a constant expression for its size

I have a newtype wrapper around an array. I assumed that I could use size_of instead of manually passing the size of the array around, but the compiler thinks I'm wrong. use std::mem::{size_of, ...
  • 997
2 votes
2 answers
2k views

How would you stream output from a Process in Rust?

This question refers to Rust as of October 2014. If you are using Rust 1.0 or above, you best look elsewhere for a solution. I have a long running Rust process that generates log values, which I'm ...
  • 31.8k
1 vote
2 answers
4k views

Cargo.toml for lib

I want to create a library for rust. This is the Cargo.toml file for my project : [package] name = "binary_tree" version = "0.0.1" authors = ["Guillaume Bersac <bersac_1@hotmail.fr>"] [lib] ...
  • 6,075
5 votes
1 answer
703 views

"borrowed value does not live long enough" when using a struct with a slice

Editor's note: The code in this question predates Rust 1.0. Since then, semantics have changed and some of the assertions made in the question are no longer true. I have the following piece of code: ...
  • 24.3k
1 vote
2 answers
4k views

How do I state that I want a struct which contains a reference to something which implements a trait?

Editor's note: The code presented in the question compiles as-is in Rust 1.0. I've tried: trait Inner {} struct Outer<'a> { inner: &'a Inner, } but the compiler complains: ...
  • 41.8k
22 votes
2 answers
12k views

Why "explicit lifetime bound required" for Box<T> in struct?

Editor's note: This code no longer produces the same error after RFC 599 was implemented, but the concepts discussed in the answers are still valid. I'm trying to compile this code: trait A { fn ...
7 votes
1 answer
4k views

How to loop over boxed iterator?

Note: This question is obsolete since Rust 1.0. The Iterator trait now has an associated type, Item, instead of a type parameter and a blanket Iterator implementation was added for Box<Iterator>....
  • 2,402
4 votes
1 answer
3k views

Cannot get Rust enum in scope when in crate

Editor's note: The code in this question is from a version of Rust prior to 1.0. The underlying system of how enums are imported was changed for Rust 1.0. This seems like it should be easy (emulating ...
14 votes
2 answers
3k views

Difference between ToString and IntoString

I'm wondering what the difference is between: "some string".to_string() And "some string".into_string() The former seems to come from ToString, which is quite clear. However, the latter seems to ...
3 votes
1 answer
5k views

Collect into owned vec of owned strings in rust

I am trying to collect into an vec of strings in rust using the following: let fields : ~[~str] = row.split_str(",").collect(); I get the following error: expected std::iter::FromIterator<&...
  • 540
2 votes
1 answer
6k views

difficulty with rust binary tree implementation

I am trying to implement a simple binary search tree in Rust but I am having difficulty pinning down an issue with inserting nodes. I am using the following data structures and functions. enum ...
7 votes
1 answer
3k views

"error: trait bounds are not allowed in structure definitions" when attempting to use polymorphism

Editor's note: This question was asked before Rust 1.0 and before certain features were implemented. The code as-is works today. I'm writing a board game AI in Rust. There are multiple rulesets for ...
  • 3,973
2 votes
1 answer
1k views

Conditional compilation in Rust 0.10?

I have been using 0.10 and recently setup a build of nightly to experiment with Box and friends. Now I have code for 0.10 using ~str and code for pre0.11 using String because of to_owned being ...
  • 3,756
3 votes
2 answers
2k views

Getting basic input for ints

I'm quite surprised I can't seem to navigate rust's documentation to find any case that describes io, could someone please explain to me how to use basic io to get user input into say, an integer? And ...
13 votes
2 answers
3k views

Why do I get "Borrowed value does not live long enough" in this example?

Editor's note: The code in this question predates Rust 1.0. The equivalent modern version of this code compiles as-is. I'm still taking baby steps at learning Rust, and was surprised at the following....
  • 44.1k
28 votes
2 answers
31k views

Use of undeclared type or module `std` when used in a separate module

I have the following code: pub mod a { #[test] pub fn test() { println!("{:?}", std::fs::remove_file("Somefilehere")); } } I get errors when I compile this: error[E0433]: failed ...
  • 964
7 votes
1 answer
7k views

Compare definite-length arrays

Editor's note: This question was asked before Rust 1.0 and uses syntax which is no longer valid. Additionally, the specific problem in this question no longer occurs in Rust 1.0. There is a struct ...
  • 1,212
26 votes
3 answers
17k views

How would you implement a bi-directional linked list in Rust?

Note that this question refers to a version of Rust before Rust 1.0. Although the syntax has changed, the concepts are still valid. You can easily implement a forwards only linked list using owned ...
  • 31.8k
1 vote
1 answer
767 views

How do I make my struct fields mutable when accessing through a shared box ptr?

Editor's note: This code is from a version of Rust prior to 1.0 and is not syntactically or semantically valid Rust 1.0 code. So, scoping out shared box pointers as a learning exercise. Purely ...
  • 3,128
6 votes
1 answer
2k views

Referencing a containing struct in Rust (and calling methods on it)

Editor's note: This code example is from a version of Rust prior to 1.0 and is not syntactically valid Rust 1.0 code. Updated versions of this code produce different errors, but the answers still ...
  • 1,187
5 votes
1 answer
692 views

Is there any difference between partially moved values and moved values in Rust?

Currently in Rust master (0.10-pre), when you move one element of a unique vector and try to move a different element, the compiler complains: let x = ~[~1, ~2, ~3]; let z0 = x[0]; let z1 = x[1]; // ...
  • 175
3 votes
1 answer
2k views

Return a closure from a function

Note that this question pertains to a version of Rust before 1.0 was released Do I understand correctly that it is now impossible to return a closure from a function, unless it was provided to the ...
62 votes
4 answers
75k views

How can I generate a random number within a range in Rust?

Editor's note: This code example is from a version of Rust prior to 1.0 and is not syntactically valid Rust 1.0 code. Updated versions of this code produce different errors, but the answers still ...
  • 9,104
3 votes
1 answer
5k views

Comparing string with static string

Here's an example of what I've tried. static TARGET: &'static str = "a string"; fn main () { printfln!("%?", TARGET.eq(~"other string")); } I looked at equiv too, but no luck. The string I ...
12 votes
4 answers
7k views

Sharing Mutable Variables Between Threads In Rust

Editor's note: This code example is from a version of Rust prior to 1.0 and is not syntactically valid Rust 1.0 code. Is it possible to share a mutable variable between multiple threads in Rust? ...
  • 1,075
2 votes
1 answer
519 views

Rust "error: moving out of immutable field"

I've created the following Rust struct: struct HTTPRequestHeader { name: ~str, data: ~str, next: Option<~HTTPRequestHeader> } And the following code to print it: fn print_headers(...
  • 12.9k
5 votes
4 answers
2k views

What is the relationship between the lifetime of a borrowed reference to a vector and the borrowed pointers it contains?

Editor's note: This code example is from a version of Rust prior to 1.0 and is not syntactically valid Rust 1.0 code. Updated versions of this code produce different errors, but the answers still ...
7 votes
1 answer
446 views

Can I borrow a pointer to a shared trait in Rust?

From the tutorial on borrowed pointers (broken), a bit modified: struct Point {x: float, y: float} fn compute(p1 : &Point) {} fn main() { let shared_box : @Point = @Point {x: 5.0, y: 1.0}; ...
  • 92.3k
65 votes
3 answers
53k views

How can I convert char to string?

This question pertains to a pre-release version of Rust. This younger question is similar. I tried to print one symbol with println: fn main() { println!('c'); } But I got next error: $ rustc ...
3 votes
1 answer
2k views

How to make Rust compiler resolve import from std?

I'm using the Rust 0.6 compiler for mingw32. I'm able to compile small programs that import from "core", but not from "std". Here is a transcript showing a trivial example and how I am compiling it: ...
19 votes
3 answers
4k 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 ...
  • 1,543
8 votes
1 answer
4k views

Constant values in Rust generics [duplicate]

Does Rust language support constant values in generic code similar to c++ way? Seems that the language overview doesn't advertise it. Parameterizing types with constants in C++ allows to create ...
user avatar
18 votes
3 answers
32k views

Two dimensional vectors in Rust

Editor's note: This question predates Rust 0.1 (tagged 2013-07-03) and is not syntactically valid Rust 1.0 code. Answers may still contain valuable information. Does anyone know how to create mutable ...
  • 2,477
2 votes
1 answer
360 views

Difference between &T and T/&, ~T and T/~

What is the difference between having the pointer type prefixing the type versus having it postfix with a slash prior to it. What does the slash even mean?
  • 1,459
3 votes
2 answers
3k views

How to initialize top-level constants with other constants?

I'd like to initialize some top-level constants using float::consts::pi. For example: import float::consts::pi; const pi2:float = pi*pi; fn main() { io::println(#fmt("pi^2=%.4f", pi2)); } I ...
  • 40k
-1 votes
1 answer
411 views

rust error "cannot determine a type for this expression"

i write a simple rust program. fn main(){ let port = 80; result::chain(connect("localhost", port as u16)) {|s| send(s,str::bytes("hello world")); }; there is some error on it. ...
  • 345
-1 votes
1 answer
145 views

"expected crate directive" error about rust

Editor's note: This question was asked before Rust 1.0 was released and the syntax, error messages, and even how crates are bundled have changed since then. i wrote a rust example program. code is ...
  • 345
35 votes
2 answers
27k views

Rust pattern matching over a vector

The tutorial shows some very basic examples of pattern matching, such as matching over an integer to emulate a c-style switch statement. The tutorial also shows how to do basic destructuring over a ...
  • 511
12 votes
3 answers
10k views

Sockets in Rust [closed]

Are there any socket or net libraries for Rust? The net page in the standard library documentation seems to only include address-related functions.
52 votes
4 answers
10k 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.