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.

The Rust programming language evolved drastically before the first stable release. Code written for Rust 0.6 can have very different syntax from code written for Rust 1.0, and sometimes entire concepts or features of the language were added or removed.

This tag is for questions that are not applicable for any stable version of Rust (e.g. 1.0.0 and up).

50 questions
71
votes
4 answers

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 contain valuable information. I came across the…
Brian Oh
  • 9,604
  • 12
  • 49
  • 68
67
votes
3 answers

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 pdst.rs pdst.rs:2:16: 2:19 error: mismatched…
Denis Kreshikhin
  • 8,856
  • 9
  • 52
  • 84
53
votes
4 answers

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.
Brad The App Guy
  • 16,255
  • 2
  • 41
  • 60
36
votes
2 answers

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 tuple type, and destructuring structures. It seems…
ash
  • 521
  • 1
  • 4
  • 8
28
votes
2 answers

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 to resolve. Use of undeclared type or module…
luke
  • 1,024
  • 3
  • 11
  • 21
27
votes
3 answers

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 pointers, something like: struct Node { next:…
Doug
  • 32,844
  • 38
  • 166
  • 222
22
votes
2 answers

Why "explicit lifetime bound required" for Box 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 f(&self); } struct S { a: Box, } and…
Eugene Zemtsov
  • 355
  • 1
  • 3
  • 7
19
votes
3 answers

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 want my closure to add its argument to an owned vector of…
Ross
  • 1,553
  • 1
  • 14
  • 22
19
votes
3 answers

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 two-dimensional vectors in Rust and pass them…
php--
  • 2,647
  • 4
  • 16
  • 18
18
votes
2 answers

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: error: the trait `core::fmt::String` is not…
ujh
  • 4,023
  • 3
  • 27
  • 31
15
votes
2 answers

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 comes from IntoString, which is less clear to…
conradkleinespel
  • 6,560
  • 10
  • 51
  • 87
13
votes
2 answers

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. I couldn't understand why this code compiles:…
Eran Medan
  • 44,555
  • 61
  • 184
  • 276
12
votes
3 answers

Sockets in Rust

Are there any socket or net libraries for Rust? The net page in the standard library documentation seems to only include address-related functions.
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
12
votes
4 answers

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? Given the following: fn main() { let mut msg =…
Evan Byrne
  • 1,105
  • 1
  • 12
  • 17
9
votes
1 answer

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(); rules(&mut builder); builder } I tried to write…
1
2 3 4