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
9
votes
1 answer

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, size_of_val}; #[repr(C, packed)] struct…
rraval
  • 1,007
  • 1
  • 9
  • 11
8
votes
1 answer

Constant values in Rust generics

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 objects with preallocated buffers of different size…
user63289
7
votes
3 answers

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 it fn main() { let mut rng = OsRng::new(); …
leshow
  • 1,568
  • 2
  • 15
  • 30
7
votes
1 answer

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. I want to define a trait method that returns an…
awelkie
  • 2,422
  • 1
  • 22
  • 32
7
votes
1 answer

"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 the game and I'd like to have the rules logic…
ujh
  • 4,023
  • 3
  • 27
  • 31
7
votes
1 answer

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 that contains the only field, a fixed-width array…
Michael Ivko
  • 1,232
  • 3
  • 13
  • 23
7
votes
1 answer

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}; compute(shared_box); } And all is fine, because…
rodrigo
  • 94,151
  • 12
  • 143
  • 190
6
votes
2 answers

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"); }); …
tshepang
  • 12,111
  • 21
  • 91
  • 136
6
votes
1 answer

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 contain valuable information. I'm trying to write a…
Kolja
  • 1,197
  • 9
  • 17
5
votes
1 answer

"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: extern crate debug; use…
tbicr
  • 24,790
  • 12
  • 81
  • 106
5
votes
1 answer

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]; // error: use of partially moved value: `x` This…
nham
  • 175
  • 1
  • 8
5
votes
4 answers

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 contain valuable information. I tried this code in…
Thomas Leonard
  • 7,068
  • 2
  • 36
  • 40
4
votes
2 answers

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 get these errors: pi2.rs:3:18: 3:20 error: constant…
sastanin
  • 40,473
  • 13
  • 103
  • 130
4
votes
1 answer

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 C/C++ enums), but I can't get it to work. I…
3
votes
1 answer

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(Decoupler::new(dtx.clone())); let mut map1 =…
Zomagk
  • 411
  • 2
  • 11